:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
  --page-bg: #0f1118;
  --card-bg: rgba(28, 31, 43, .96);
  --border: #35394c;
  --muted: #aeb4c5;
  --radius: 18px;
}

* { box-sizing: border-box; }

html {
  width: 100%;
  min-height: 100%;
  font-size: 18px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 18% 0%, rgba(72, 78, 120, .34), transparent 34%),
    radial-gradient(circle at 84% 8%, rgba(91, 62, 145, .2), transparent 30%),
    var(--page-bg);
  color: #f7f7fb;
}

.shell {
  width: 100%;
  min-height: 100dvh;
  margin: 0;
  padding:
    max(16px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(26px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 4px 4px 6px;
}

header > div:last-child { min-width: 0; }

h1 {
  margin: 0;
  font-size: clamp(1.7rem, 7vw, 2.25rem);
  line-height: 1.15;
  overflow-wrap: anywhere;
}

header p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.45;
}

.badge {
  flex: 0 0 auto;
  padding: 6px 8px;
  border-radius: 9px;
  background: #ff5a67;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .08em;
}

.card {
  width: 100%;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 17px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .18);
  backdrop-filter: blur(12px);
}

.controls,
.diagnostics {
  flex: 0 0 auto;
}

.control-grid,
.transcript-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

label {
  display: block;
  margin-bottom: 9px;
  font-size: 1rem;
  font-weight: 750;
}

select,
button {
  width: 100%;
  max-width: 100%;
  min-height: 54px;
  border-radius: 13px;
  border: 1px solid #454b61;
  font: inherit;
  font-size: 1rem;
}

select {
  padding: 13px 14px;
  background: #11131b;
  color: #fff;
}

.status-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin: 3px 2px 13px;
  color: #cbd0df;
  font-size: 1rem;
}

#status {
  min-width: 0;
  overflow-wrap: anywhere;
}

.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #73798b;
}

.dot.active {
  background: #4ee39a;
  box-shadow: 0 0 14px #4ee39a;
}

.dot.error { background: #ff6673; }

.buttons {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

button {
  padding: 14px 12px;
  background: #2c3040;
  color: #fff;
  font-weight: 760;
  cursor: pointer;
  touch-action: manipulation;
}

button.primary {
  background: linear-gradient(135deg, #7268ff, #9f69ff);
  border-color: transparent;
}

button:disabled {
  opacity: .42;
  cursor: not-allowed;
}

.audio-note {
  margin-top: 14px;
  padding: 13px 14px;
  border: 1px solid rgba(135, 143, 177, .28);
  border-radius: 13px;
  background: rgba(16, 18, 27, .52);
  color: #b8bfd2;
  font-size: .96rem;
  line-height: 1.65;
}

.audio-note strong { color: #f0f2f8; }

.transcript-grid {
  flex: 1 1 auto;
  min-height: 0;
  grid-template-rows: minmax(0, 1fr) minmax(0, 1.08fr);
}

.transcript {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  flex: 0 0 auto;
}

h2 {
  margin: 0;
  font-size: 1.12rem;
  color: #d5daea;
}

.label-pill {
  flex: 0 0 auto;
  padding: 5px 9px;
  border: 1px solid #4e566e;
  border-radius: 999px;
  color: #8992aa;
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .08em;
}

.label-pill.translated {
  border-color: rgba(157, 105, 255, .58);
  color: #c7afff;
}

.text {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.78;
  font-size: 1.12rem;
  padding-right: 3px;
}

.output .text {
  font-size: 1.22rem;
  line-height: 1.82;
}

.muted { color: #858da3; }
summary { cursor: pointer; font-size: 1rem; }

pre {
  max-width: 100%;
  overflow-x: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #aeb5c8;
  font-size: .86rem;
}

footer {
  flex: 0 0 auto;
  text-align: center;
  color: #9ea5b8;
  font-size: .9rem;
  line-height: 1.55;
  margin-top: 2px;
  padding: 0 8px;
}

/* 平板維持上下排列，但適度擴展寬度與字體。 */
@media (min-width: 700px) {
  .shell {
    max-width: 900px;
    margin: 0 auto;
    padding: 28px 24px 36px;
  }

  .card { padding: 21px; }
  .transcript-grid { grid-template-rows: minmax(260px, .95fr) minmax(300px, 1.05fr); }
  .text { font-size: 1.18rem; }
  .output .text { font-size: 1.28rem; }
}

/* 只有真正的桌機寬螢幕與滑鼠環境才讓原文/翻譯左右並排。 */
@media (min-width: 1100px) and (hover: hover) and (pointer: fine) {
  .shell { max-width: 1180px; }
  .control-grid {
    grid-template-columns: minmax(280px, .85fr) minmax(420px, 1.15fr);
    align-items: end;
  }
  .transcript-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: unset;
    gap: 16px;
  }
}

/* v1.5：手機版同時放大字體，並把下方空白讓給原文與翻譯區。 */
@media (max-width: 699px) {
  html { font-size: 20px; }

  .shell {
    gap: 10px;
    padding:
      max(14px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(20px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  header { margin: 4px 2px 4px; }
  h1 { font-size: clamp(1.65rem, 8vw, 2.05rem); }
  header p { font-size: .94rem; }
  .badge { font-size: .68rem; }

  .card {
    padding: 16px;
    border-radius: 16px;
  }

  label { font-size: 1rem; }
  select, button {
    min-height: 56px;
    font-size: 1rem;
  }

  .status-row { font-size: .95rem; }
  .audio-note {
    font-size: .94rem;
    line-height: 1.7;
  }

  h2 { font-size: 1.08rem; }
  .label-pill { font-size: .64rem; }

  .transcript-grid {
    grid-template-rows: minmax(190px, .9fr) minmax(220px, 1.1fr);
    gap: 10px;
  }

  .text {
    font-size: 1.24rem;
    line-height: 1.74;
  }

  .output .text {
    font-size: 1.42rem;
    line-height: 1.8;
  }

  summary { font-size: .98rem; }
  footer { font-size: .8rem; }
}

@media (max-width: 380px) {
  html { font-size: 19px; }
  .buttons { grid-template-columns: 1fr; }
  .transcript-grid { grid-template-rows: minmax(180px, .9fr) minmax(210px, 1.1fr); }
}

/* v1.7：以明確 px 與 !important 強制手機大字，避免 rem、舊規則或瀏覽器文字縮放抵銷。 */
@media screen and (max-width: 699px) {
  body {
    font-size: 18px !important;
  }

  h1 {
    font-size: 32px !important;
    line-height: 1.15 !important;
  }

  header p {
    font-size: 17px !important;
    line-height: 1.45 !important;
  }

  .badge {
    font-size: 12px !important;
  }

  label,
  #status,
  #timer,
  summary {
    font-size: 18px !important;
  }

  select,
  button {
    min-height: 58px !important;
    font-size: 18px !important;
  }

  .audio-note {
    font-size: 17px !important;
    line-height: 1.65 !important;
  }

  h2 {
    font-size: 20px !important;
  }

  .label-pill {
    font-size: 11px !important;
  }

  .text {
    font-size: 27px !important;
    line-height: 1.58 !important;
    letter-spacing: .01em !important;
  }

  .output .text {
    font-size: 32px !important;
    line-height: 1.62 !important;
  }

  footer {
    font-size: 14px !important;
  }
}


/*
v1.8：不再只依賴 max-width。
部分 Android 瀏覽器或「電腦版網站」會使用約 980px 的 layout viewport，
導致原本 max-width:699px 的手機大字規則完全不會啟動。
以下規則改由 JS 偵測觸控裝置後套用。
*/
html.touch-ui {
  font-size: 22px !important;
}

html.touch-ui body {
  font-size: 20px !important;
}

html.touch-ui .shell {
  max-width: none !important;
  width: 100% !important;
}

html.touch-ui h1 {
  font-size: clamp(34px, 5.2vw, 46px) !important;
  line-height: 1.12 !important;
}

html.touch-ui header p {
  font-size: clamp(18px, 2.5vw, 23px) !important;
}

html.touch-ui .badge {
  font-size: 13px !important;
}

html.touch-ui label,
html.touch-ui #status,
html.touch-ui #timer,
html.touch-ui summary {
  font-size: clamp(18px, 2.45vw, 23px) !important;
}

html.touch-ui select,
html.touch-ui button {
  min-height: 60px !important;
  font-size: clamp(18px, 2.5vw, 23px) !important;
}

html.touch-ui .audio-note {
  font-size: clamp(17px, 2.3vw, 21px) !important;
  line-height: 1.6 !important;
}

html.touch-ui h2 {
  font-size: clamp(21px, 2.9vw, 27px) !important;
}

html.touch-ui .label-pill {
  font-size: 12px !important;
}

html.touch-ui .text {
  font-size: clamp(30px, 4.4vw, 42px) !important;
  line-height: 1.55 !important;
}

html.touch-ui .output .text {
  font-size: clamp(36px, 5.2vw, 50px) !important;
  line-height: 1.58 !important;
}

html.touch-ui footer {
  font-size: clamp(14px, 2vw, 18px) !important;
}

