:root {
  color-scheme: dark;
  --bg: #06080d;
  --bg-2: #0c1018;
  --panel: rgba(20, 26, 38, .72);
  --panel-strong: rgba(20, 26, 38, .92);
  --line: rgba(255, 255, 255, .08);
  --line-strong: rgba(255, 255, 255, .14);
  --text: #f5f7fb;
  --muted: #8b96ad;
  --muted-2: #5d6779;
  --accent: #7aa7ff;
  --accent-soft: rgba(122, 167, 255, .14);
  --live: #4ade80;
  --error: #ff6b7a;
  --hero: #ffe27a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100svh;
  background:
    radial-gradient(60rem 40rem at 18% -10%, rgba(122, 167, 255, .18), transparent 60%),
    radial-gradient(48rem 30rem at 100% 0%, rgba(74, 222, 128, .10), transparent 55%),
    var(--bg);
}

button, select { font: inherit; }
button { cursor: pointer; }

/* レイアウト全体 */
.app {
  width: min(100%, 720px);
  min-height: 100svh;
  margin: 0 auto;
  padding:
    max(14px, env(safe-area-inset-top)) 16px
    max(24px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto auto auto auto auto 1fr auto auto auto;
  gap: 14px;
}

/* トップバー */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 2px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 14px var(--accent);
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.brand-eyebrow {
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.brand-name {
  margin: 0;
  color: var(--text);
  font-size: clamp(18px, 4.6vw, 22px);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

/* ステータスバナー（翻訳中シグナル） */
.status-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 22px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: .05em;
  color: var(--muted);
  transition: all .25s ease;
}

.status-banner-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}

.status-banner-text {
  white-space: nowrap;
}

.status-banner.idle {
  color: var(--muted);
}

.status-banner.live {
  color: #0a1f12;
  border-color: var(--live);
  background:
    linear-gradient(90deg, var(--live) 0%, #6ee79c 100%);
  box-shadow:
    0 0 0 1px rgba(74, 222, 128, .2),
    0 12px 40px rgba(74, 222, 128, .35);
  font-size: 17px;
}

.status-banner.live .status-banner-dot {
  background: #0a1f12;
  box-shadow: 0 0 0 0 rgba(10, 31, 18, .6);
  animation: live-pulse 1.4s ease-in-out infinite;
}

.status-banner.live .status-banner-text::after {
  content: " LIVE";
  margin-left: 4px;
  font-weight: 900;
  letter-spacing: .12em;
}

.status-banner.error {
  color: #fff;
  border-color: var(--error);
  background: var(--error);
  box-shadow: 0 10px 30px rgba(255, 107, 122, .35);
}

.status-banner.error .status-banner-dot {
  background: #fff;
}

@keyframes live-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(10, 31, 18, .55); transform: scale(1); }
  70%  { box-shadow: 0 0 0 10px rgba(10, 31, 18, 0); transform: scale(1.15); }
  100% { box-shadow: 0 0 0 0 rgba(10, 31, 18, 0); transform: scale(1); }
}

/* 言語スイッチャー（Apple Translate 風のピル） */
.lang-switcher {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
  padding: 6px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.lang-select {
  width: 100%;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  padding: 12px 32px 12px 14px;
  font-size: 16px;
  font-weight: 700;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%238b96ad' d='M5 6 0 0h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  text-align: left;
  outline: none;
}

.lang-select:focus-visible {
  background-color: var(--accent-soft);
}

.swap {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--bg-2);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform .25s ease, background .2s ease, color .2s ease;
}

.swap:hover { background: var(--accent-soft); color: var(--text); }
.swap:active { transform: rotate(180deg); }

/* クイックペア（チップ） */
.quick-pairs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 2px 4px;
  scrollbar-width: none;
}

.quick-pairs::-webkit-scrollbar { display: none; }

.quick-pairs button {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  transition: all .15s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.quick-pairs button:hover {
  border-color: var(--line-strong);
  color: var(--text);
}

.quick-pairs button.active {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

/* 言語注記 */
.lang-note {
  margin: -4px 4px 0;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

.lang-note-icon {
  flex: 0 0 auto;
  color: var(--accent);
  font-weight: 800;
}

/* ヒーロー字幕エリア */
.caption-hero {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 12px;
  padding: 24px 18px 18px;
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(122, 167, 255, .04) 0%, transparent 60%),
    var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .35);
  min-height: 280px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.translation {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8px;
  color: var(--hero);
  font-size: clamp(30px, 7.6vw, 48px);
  line-height: 1.22;
  font-weight: 800;
  letter-spacing: -0.015em;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  text-wrap: balance;
  text-shadow: 0 2px 18px rgba(0, 0, 0, .55);
  transition: opacity .2s ease;
}

.translation.placeholder-text {
  color: var(--muted-2);
  font-size: clamp(18px, 4.4vw, 22px);
  font-weight: 600;
  letter-spacing: 0;
  text-shadow: none;
}

.translation.live-text { color: var(--hero); }

.transcript {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
  padding: 12px 4px 0;
  border-top: 1px dashed var(--line);
  min-height: 38px;
}

/* ドック（中央配置の大きなマイクボタン） */
.dock {
  display: grid;
  grid-template-columns: 1fr auto auto 1fr;
  gap: 12px;
  align-items: center;
  padding: 4px 0;
}

.toggle {
  grid-column: 1;
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}

.toggle:hover {
  color: var(--text);
  border-color: var(--line-strong);
}

.toggle-icon {
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  transition: color .15s ease;
}

.toggle-label {
  letter-spacing: .02em;
}

/* iOS風スイッチ */
.toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-switch {
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid var(--line-strong);
  transition: background .2s ease, border-color .2s ease;
  flex: 0 0 auto;
}

.toggle-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
  transition: transform .2s cubic-bezier(.34, 1.56, .64, 1);
}

.toggle:has(input:checked) {
  color: var(--text);
  border-color: rgba(122, 167, 255, .4);
  background: rgba(122, 167, 255, .08);
}

.toggle:has(input:checked) .toggle-icon {
  color: var(--accent);
}

.toggle:has(input:checked) .toggle-switch {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle:has(input:checked) .toggle-switch::after {
  transform: translateX(16px);
}

.mic-btn {
  grid-column: 2;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(180deg, #8db4ff 0%, #5a8aef 100%);
  color: #06111f;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 14px 40px rgba(122, 167, 255, .35),
    inset 0 1px 0 rgba(255, 255, 255, .35);
  transition: transform .15s ease, box-shadow .2s ease;
}

.mic-btn:hover { transform: translateY(-2px); }
.mic-btn:active { transform: translateY(0); }

.mic-btn:disabled {
  background: linear-gradient(180deg, #2a3142 0%, #1a1f2c 100%);
  color: var(--muted-2);
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

.mic-btn.stop {
  grid-column: 3;
  width: 60px;
  height: 60px;
  background: linear-gradient(180deg, #ff8d97 0%, #e85565 100%);
  color: #2a0a0e;
  box-shadow:
    0 10px 30px rgba(232, 85, 101, .35),
    inset 0 1px 0 rgba(255, 255, 255, .25);
}

.mic-btn.stop:disabled {
  background: linear-gradient(180deg, #2a3142 0%, #1a1f2c 100%);
}

/* 履歴パネル */
.history-panel {
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  overflow: hidden;
}

.history-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  list-style: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  user-select: none;
}

.history-panel summary::-webkit-details-marker { display: none; }
.history-panel summary::after {
  content: "▾";
  color: var(--muted);
  transition: transform .2s ease;
}

.history-panel[open] summary::after { transform: rotate(180deg); }

.history {
  display: grid;
  gap: 10px;
  padding: 0 14px 14px;
  max-height: 30svh;
  overflow-y: auto;
}

.history:empty::after {
  content: "まだ履歴はありません。";
  color: var(--muted-2);
  font-size: 13px;
  padding: 6px 0 8px;
}

.history-item {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .03);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  border-left: 3px solid var(--accent);
}

.history-item small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

button.ghost {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

button.ghost:hover {
  color: var(--text);
  border-color: var(--line-strong);
}

/* ステータス */
.status {
  margin: 0;
  text-align: center;
  color: var(--muted-2);
  font-size: 12px;
  line-height: 1.6;
}

/* 大画面 */
@media (min-width: 720px) {
  .caption-hero {
    min-height: 360px;
    padding: 32px 24px 24px;
  }

  .mic-btn { width: 84px; height: 84px; }
  .mic-btn.stop { width: 64px; height: 64px; }
}

/* タップターゲット最適化（スマホ） */
@media (hover: none) {
  .swap:hover { background: var(--bg-2); color: var(--accent); }
  .quick-pairs button:hover { color: var(--muted); }
}
