/* ミライリプレイ装置 v0.1 ── プロトタイプ Phase 0 + 特許デモ */

:root {
  --bg-main: #fdf6e3;
  --bg-left: #fbeec9;
  --bg-right: #fdf6e3;
  --bg-card: #fffaeb;
  --bg-card-active: #ffe9a8;
  --bg-card-master: #fff3d6;
  --accent: #d97706;
  --accent-warm: #b45309;
  --text-main: #3d2914;
  --text-mute: #8b6f47;
  --border: #e6d3a3;
  --border-active: #d97706;
  --master-color: #b45309;
  --ai-color: #1e6091;
  --mirai-color: #c2185b;
  --translation-color: #6b5d3f;
  --error: #c0392b;
  --success: #27ae60;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  background: var(--bg-main);
  color: var(--text-main);
  font-size: 15px;
  line-height: 1.7;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-rows: 56px 1fr 56px;
  height: 100vh;
}

/* ========== Header ========== */
header {
  display: flex;
  align-items: center;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(90deg, #faedcd 0%, #fdf6e3 100%);
  gap: 24px;
}

header h1 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
}

header h1 span.subtitle {
  color: var(--text-mute);
  font-weight: 400;
  font-size: 13px;
  margin-left: 12px;
}

header nav {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

header nav button {
  padding: 6px 16px;
  background: transparent;
  color: var(--text-mute);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: all 0.15s;
}

header nav button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}

header nav button:hover:not(.active) {
  color: var(--text-main);
  border-color: var(--accent);
}

/* ========== Main ========== */
main {
  display: grid;
  grid-template-columns: 38% 62%;
  overflow: hidden;
}

/* ========== Left: Mirai standby ========== */
#left-panel {
  background: var(--bg-left);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 28px 28px 24px;
  overflow-y: auto;
}

.mirai-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.mirai-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffc4dd 0%, #ff9ec7 50%, #d97aae 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  box-shadow: 0 0 32px rgba(255, 158, 199, 0.35);
  animation: mirai-pulse 3.2s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes mirai-pulse {
  0%, 100% { box-shadow: 0 0 24px rgba(255, 158, 199, 0.3); }
  50% { box-shadow: 0 0 40px rgba(255, 158, 199, 0.55); }
}

.mirai-name {
  font-size: 22px;
  font-weight: 600;
  color: var(--mirai-color);
  letter-spacing: 0.06em;
}

.mirai-role {
  font-size: 12px;
  color: var(--text-mute);
  margin-top: 4px;
}

.mirai-speech {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--mirai-color);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 20px;
  font-size: 15px;
  line-height: 1.85;
  color: var(--text-main);
  white-space: pre-wrap;
  min-height: 120px;
  position: relative;
}

.mirai-speech::before {
  content: "ミライ";
  position: absolute;
  top: -10px;
  left: 16px;
  font-size: 11px;
  background: var(--bg-left);
  color: var(--mirai-color);
  padding: 0 8px;
  letter-spacing: 0.1em;
}

.mirai-speech.cursor::after {
  content: "▋";
  color: var(--mirai-color);
  animation: blink 0.8s steps(1) infinite;
}

@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.mirai-context {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px dashed var(--border);
  font-size: 12px;
  color: var(--text-mute);
}

.mirai-context dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
}

.mirai-context dt {
  color: var(--mirai-color);
  font-weight: 600;
}

/* ========== Right: content area ========== */
#right-panel {
  background: var(--bg-right);
  overflow-y: auto;
  padding: 28px 32px;
  position: relative;
}

/* ---- View: Replay ---- */
.view-replay .turn {
  background: transparent;
  border: none;
  padding: 8px 0 12px;
  margin-bottom: 8px;
  transition: opacity 0.4s;
  opacity: 0.55;
}

.view-replay .turn.active { opacity: 1; }
.view-replay .turn.past { opacity: 0.85; }

.turn-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.turn-num {
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--accent);
  font-weight: 700;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 999px;
}

.view-replay .turn.active .turn-num {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ===== 吹き出し (bubble) ===== */
.block {
  position: relative;
  margin-bottom: 14px;
  max-width: 88%;
  border-radius: 16px;
  padding: 14px 18px 14px 18px;
  border: 1px solid;
}

.block:last-child { margin-bottom: 0; }

.block.hidden { display: none; }

.block.appearing {
  animation: bubble-pop 0.45s ease-out;
}

@keyframes bubble-pop {
  0% { opacity: 0; transform: translateY(10px) scale(0.96); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.block.master {
  background: #fff3d6;
  border-color: #e8cc8e;
  margin-left: auto;
  margin-right: 0;
  border-bottom-right-radius: 4px;
}

.block.ai {
  background: #e3f2fd;
  border-color: #b3d4f1;
  margin-right: auto;
  margin-left: 0;
  border-bottom-left-radius: 4px;
}

/* tail (尻尾) — 簡易 */
.block.master::after {
  content: "";
  position: absolute;
  right: -6px;
  bottom: 6px;
  width: 14px;
  height: 14px;
  background: #fff3d6;
  border-right: 1px solid #e8cc8e;
  border-bottom: 1px solid #e8cc8e;
  transform: rotate(-45deg);
  border-bottom-right-radius: 3px;
}

.block.ai::after {
  content: "";
  position: absolute;
  left: -6px;
  bottom: 6px;
  width: 14px;
  height: 14px;
  background: #e3f2fd;
  border-left: 1px solid #b3d4f1;
  border-bottom: 1px solid #b3d4f1;
  transform: rotate(45deg);
  border-bottom-left-radius: 3px;
}

.speaker-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

/* Master のラベルも左寄せ（吹き出し全体は右寄せのまま）*/

.speaker-icon {
  font-size: 20px;
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.speaker-icon svg {
  width: 26px;
  height: 26px;
}

.tachikoma-svg { display: block; }

.speaker-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.block.master .speaker-label { color: var(--master-color); }
.block.ai .speaker-label { color: var(--ai-color); }

.block-text {
  white-space: pre-wrap;
  font-size: 14.5px;
  line-height: 1.85;
  padding: 0;
}

.block.master .block-text {
  color: #5b3a18;
  font-weight: 500;
  text-align: left;
}

.translation {
  margin-top: 12px;
  padding: 10px 14px;
  background: rgba(180, 83, 9, 0.08);
  border-left: 2px solid var(--translation-color);
  font-size: 12.5px;
  font-style: italic;
  color: var(--translation-color);
  border-radius: 0 6px 6px 0;
  line-height: 1.65;
}

.translation::before {
  content: "（一般語訳） ";
  font-style: normal;
  font-weight: 700;
  color: var(--accent-warm);
}

/* prologue / epilogue */
.prologue, .epilogue {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 28px;
  margin-bottom: 20px;
}

.prologue h2, .epilogue h2 {
  font-size: 16px;
  color: var(--accent);
  margin-bottom: 12px;
}

.prologue p, .epilogue p {
  font-size: 14px;
  color: var(--text-main);
  line-height: 1.85;
}

.prologue .meta {
  color: var(--text-mute);
  font-size: 12px;
  margin-top: 12px;
}

/* ---- View: Patents ---- */
.view-patents h2 {
  font-size: 18px;
  margin-bottom: 16px;
  color: var(--accent);
}

.view-patents .description {
  color: var(--text-mute);
  font-size: 13px;
  margin-bottom: 24px;
  line-height: 1.7;
}

.patent-list {
  display: grid;
  gap: 16px;
}

.patent-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  cursor: pointer;
  transition: all 0.15s;
}

.patent-card:hover {
  border-color: var(--accent);
  background: var(--bg-card-active);
}

.patent-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.patent-code {
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 4px;
  letter-spacing: 0.05em;
}

.patent-class {
  background: var(--bg-card);
  color: var(--accent-warm);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 3px;
  border: 1px solid var(--border);
}

.patent-title {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
}

.patent-summary {
  font-size: 13.5px;
  color: var(--text-mute);
  line-height: 1.75;
  margin-top: 8px;
}

.patent-claims {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
  font-size: 12.5px;
  color: var(--text-main);
}

.patent-claims-title {
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--accent-warm);
  margin-bottom: 8px;
}

.patent-claims ul {
  list-style: none;
  padding-left: 12px;
}

.patent-claims li {
  margin-bottom: 4px;
}

.patent-claims li::before {
  content: "▸ ";
  color: var(--accent);
}

/* voice config modal */
#voice-modal {
  position: fixed;
  inset: 0;
  background: rgba(40, 25, 10, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 32px;
}
#voice-modal.show { display: flex; }

#voice-modal-content {
  background: var(--bg-left);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: min(720px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

#voice-modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#voice-modal-close, #voice-save, #voice-preview-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}
#voice-save.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}

#voice-modal-body { padding: 18px 24px; overflow-y: auto; }
.voice-modal-desc { font-size: 13px; color: var(--text-mute); margin-bottom: 16px; line-height: 1.6; }

.voice-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.voice-table th, .voice-table td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: center; }
.voice-table th { color: var(--accent); font-weight: 700; letter-spacing: 0.05em; font-size: 12px; }
.voice-table td:first-child { text-align: left; font-weight: 500; }
.voice-table button.preview-btn {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}
.voice-table button.preview-btn.playing { background: var(--accent); color: #fff; border-color: var(--accent); }

.voice-modal-footer { margin-top: 16px; display: flex; gap: 12px; align-items: center; justify-content: flex-end; }

/* patent detail modal */
#patent-detail {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 32px;
}

#patent-detail.show { display: flex; }

#patent-detail-content {
  background: var(--bg-left);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: min(900px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

#patent-detail-header {
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#patent-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  white-space: pre-wrap;
  font-family: -apple-system, "Hiragino Sans", "Meiryo", sans-serif;
  font-size: 13.5px;
  line-height: 1.85;
}

#patent-detail-close {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
}

/* ---- View: Question ---- */
.view-question {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.view-question h2 {
  font-size: 18px;
  margin-bottom: 8px;
  color: var(--accent);
}

.view-question .description {
  color: var(--text-mute);
  font-size: 13px;
  margin-bottom: 16px;
}

.qa-history {
  flex: 1;
  overflow-y: auto;
  margin-bottom: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}

.qa-empty {
  color: var(--text-mute);
  font-style: italic;
  text-align: center;
  padding: 40px 0;
}

.qa-block {
  margin-bottom: 24px;
}

.qa-block:last-child { margin-bottom: 0; }

.qa-q, .qa-a {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 8px;
  white-space: pre-wrap;
  line-height: 1.8;
}

.qa-q {
  background: rgba(180, 83, 9, 0.1);
  border-left: 3px solid var(--master-color);
  font-size: 14px;
  color: #5b3a18;
}

.qa-q::before {
  content: "Q ";
  font-weight: 700;
  color: var(--master-color);
}

.qa-a {
  background: rgba(30, 96, 145, 0.08);
  border-left: 3px solid var(--ai-color);
  font-size: 14px;
}

.qa-a::before {
  content: "A ";
  font-weight: 700;
  color: var(--accent);
}

.qa-loading::after {
  content: " 思考中…";
  color: var(--text-mute);
  font-style: italic;
}

.qa-input-row {
  display: flex;
  gap: 8px;
}

.qa-input-row select {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 12px;
  font-family: inherit;
  font-size: 13px;
}

.qa-input-row textarea {
  flex: 1;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  min-height: 56px;
}

.qa-input-row button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0 20px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
}

.qa-input-row button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---- View: Drafting ---- */
.view-draft {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.view-draft h2 {
  font-size: 18px;
  margin-bottom: 8px;
  color: var(--accent);
}

.view-draft .description {
  color: var(--text-mute);
  font-size: 13px;
  margin-bottom: 16px;
}

.draft-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 16px;
}

.draft-form label {
  display: block;
  font-size: 12px;
  letter-spacing: 0.05em;
  color: var(--accent-warm);
  margin-bottom: 6px;
  margin-top: 12px;
}

.draft-form label:first-child { margin-top: 0; }

.draft-form input, .draft-form textarea {
  width: 100%;
  background: var(--bg-main);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13.5px;
  resize: vertical;
}

.draft-form textarea { min-height: 90px; }

.draft-form button {
  margin-top: 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px 20px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
}

.draft-form button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.draft-output {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  overflow-y: auto;
  white-space: pre-wrap;
  font-family: -apple-system, "Hiragino Sans", "Meiryo", sans-serif;
  font-size: 13.5px;
  line-height: 1.85;
  min-height: 200px;
}

.draft-output.empty {
  color: var(--text-mute);
  font-style: italic;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ========== Footer (controls) ========== */
footer {
  border-top: 1px solid var(--border);
  background: var(--bg-left);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}

footer .progress {
  flex: 1;
  height: 6px;
  background: var(--bg-main);
  border-radius: 3px;
  overflow: hidden;
}

footer .progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--mirai-color));
  width: 0%;
  transition: width 0.5s;
}

footer button {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 14px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

footer button:hover {
  border-color: var(--accent);
}

footer button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}

footer button.active {
  border-color: var(--mirai-color);
  color: var(--mirai-color);
  font-weight: 600;
}

footer .speed-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-mute);
}

footer select {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 8px;
  font-family: inherit;
  font-size: 12px;
}

footer .turn-indicator {
  font-size: 12px;
  color: var(--text-mute);
  letter-spacing: 0.05em;
  min-width: 70px;
  text-align: right;
}

/* scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-main); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* status badge (footer 内) */
.llm-status {
  font-size: 11px;
  color: var(--text-mute);
  letter-spacing: 0.05em;
  white-space: nowrap;
  flex-shrink: 0;
}

.llm-status .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-mute);
  margin-right: 6px;
  vertical-align: middle;
}

.llm-status.online .dot { background: var(--success); box-shadow: 0 0 8px rgba(118,255,160,0.6); }
.llm-status.offline .dot { background: var(--error); }

/* responsive (PC前提だが小さい時は縦) */
@media (max-width: 1024px) {
  main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  #left-panel { border-right: none; border-bottom: 1px solid var(--border); padding: 16px 20px; }
  .mirai-context { display: none; }
}
