/* Shared look for the viewer (phones) and operator (laptop) pages. */

:root {
  color-scheme: light dark;
  --bg: #f7f5f1;
  --surface: #ffffff;
  --text: #1d1b18;
  --muted: #6a655d;
  --line: #e2ddd4;
  --accent: #1f5f7a;
  --accent-text: #ffffff;
  --live: #b3261e;
  --ok: #1e7a4c;
  --alert-bg: #fff4e2;
  --alert-text: #663c00;
  --alert-line: #efc98c;
  --caption-size: 1.375rem;
  --radius: 12px;
  --font: system-ui, -apple-system, 'Segoe UI', 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR',
    'PingFang SC', 'PingFang TC', 'Microsoft YaHei', 'Microsoft JhengHei', 'Noto Sans SC', 'Noto Sans TC',
    sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101418;
    --surface: #1a2026;
    --text: #f1eee8;
    --muted: #a49e93;
    --line: #2d353d;
    --accent: #86c1d8;
    --accent-text: #0c1a21;
    --live: #ff8a80;
    --ok: #6fd3a0;
    --alert-bg: #382b12;
    --alert-text: #ffd699;
    --alert-line: #6a5121;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
}

h1,
h2,
p {
  margin: 0;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  min-height: 44px;
  padding: 0 1rem;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---------------- Viewer ---------------- */

.viewer {
  min-height: 100dvh;
}

.viewer-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: calc(0.6rem + env(safe-area-inset-top)) calc(1rem + env(safe-area-inset-right)) 0.6rem
    calc(1rem + env(safe-area-inset-left));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.viewer-bar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.viewer-bar h1 {
  font-size: 1rem;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.font-controls {
  display: flex;
  gap: 0.4rem;
  flex: none;
}

.font-controls button {
  min-width: 44px;
  padding: 0 0.6rem;
  font-weight: 600;
}

#font-larger {
  font-size: 1.15rem;
}

.languages {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.4rem;
  margin-top: 0.6rem;
}

.languages button {
  padding: 0 0.25rem;
  font-size: 0.95rem;
  white-space: nowrap;
}

.languages button[aria-pressed='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

#status {
  margin-top: 0.55rem;
  font-size: 0.85rem;
  color: var(--muted);
}

#status[data-state='live'] {
  color: var(--live);
  font-weight: 600;
}

#status[data-state='live']::before {
  content: '';
  display: inline-block;
  width: 0.55em;
  height: 0.55em;
  margin-right: 0.45em;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.6s ease-in-out infinite;
}

#captions {
  padding: 1.1rem calc(1.1rem + env(safe-area-inset-right)) calc(6rem + env(safe-area-inset-bottom))
    calc(1.1rem + env(safe-area-inset-left));
}

.line {
  margin-bottom: 0.8em;
  font-size: var(--caption-size);
  line-height: 1.45;
  overflow-wrap: anywhere;
  color: color-mix(in srgb, var(--text) 62%, var(--bg));
  transition: color 0.4s ease;
}

.line:last-child {
  color: var(--text);
}

.line.pending::after {
  content: '…';
  color: var(--muted);
  animation: pulse 1.2s ease-in-out infinite;
}

#jump {
  position: fixed;
  left: 50%;
  bottom: calc(1.1rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  border-radius: 999px;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  box-shadow: 0 4px 14px rgb(0 0 0 / 25%);
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------------- Operator ---------------- */

.operator {
  padding: 1.25rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.operator h2 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.operator label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.operator input,
.operator textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.operator textarea {
  resize: vertical;
  line-height: 1.5;
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
}

.quiet {
  background: transparent;
  color: var(--muted);
}

.alert {
  background: var(--alert-bg);
  color: var(--alert-text);
  border: 1px solid var(--alert-line);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
}

.alert .muted {
  color: inherit;
  opacity: 0.85;
  margin-top: 0.4rem;
}

.login {
  min-height: calc(100dvh - 2.5rem);
  display: grid;
  place-items: center;
}

.login .card {
  width: min(100%, 24rem);
  display: grid;
  gap: 0.75rem;
}

.login h1 {
  font-size: 1.35rem;
}

.op-header {
  max-width: 72rem;
  margin: 0 auto 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.op-header h1 {
  display: inline;
  font-size: 1.3rem;
  margin-right: 0.6rem;
}

.pill {
  display: inline-block;
  padding: 0.15rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  vertical-align: 0.15em;
}

.pill[data-live='true'] {
  border-color: var(--live);
  color: var(--live);
}

.counts {
  display: flex;
  gap: 0.5rem;
  margin: 0;
}

.counts div {
  min-width: 4.5rem;
  padding: 0.35rem 0.7rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: center;
}

.counts dt {
  font-size: 0.75rem;
  color: var(--muted);
}

.counts dd {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.op-grid {
  max-width: 72rem;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18rem;
  gap: 1rem;
  align-items: start;
}

.control {
  display: grid;
  gap: 0.9rem;
}

.big {
  min-height: 64px;
  font-size: 1.3rem;
}

.big[data-live='true'] {
  background: var(--live);
  border-color: var(--live);
  color: var(--surface);
}

.mic {
  color: var(--muted);
}

.mic::before {
  content: '';
  display: inline-block;
  width: 0.65em;
  height: 0.65em;
  margin-right: 0.5em;
  border-radius: 50%;
  background: currentColor;
}

.mic[data-state='listening'] {
  color: var(--ok);
  font-weight: 600;
}

.mic[data-state='listening']::before {
  animation: pulse 1.4s ease-in-out infinite;
}

.mic[data-state='blocked'],
.mic[data-state='no-mic'],
.mic[data-state='speech-offline'] {
  color: var(--alert-text);
  background: var(--alert-bg);
  border: 1px solid var(--alert-line);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
}

.mode {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

.mode legend {
  padding: 0;
  margin-bottom: 0.4rem;
  font-weight: 600;
}

.mode-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.operator .mode-options label {
  flex: 1 1 13rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem 0.5rem;
  margin: 0;
  min-height: 48px;
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

.operator .mode-options label:has(input:checked) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}

.operator .mode-options input {
  width: auto;
  min-height: 0;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}

.mode-options .muted {
  font-weight: 400;
}

.interim {
  min-height: 3.4em;
  font-size: 1.15rem;
  color: var(--muted);
}

.manual-row {
  display: flex;
  gap: 0.5rem;
}

.manual-row button {
  flex: none;
}

.share {
  display: grid;
  gap: 0.6rem;
  justify-items: center;
  text-align: center;
}

.share img {
  width: 100%;
  max-width: 220px;
  height: auto;
  background: #ffffff;
  border-radius: 8px;
  padding: 6px;
}

.url {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.log-card,
.settings {
  grid-column: 1 / -1;
}

#log {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 24rem;
  overflow-y: auto;
}

.entry {
  padding: 0.7rem 0;
  border-top: 1px solid var(--line);
}

.entry:first-child {
  border-top: 0;
}

.entry .source {
  color: var(--muted);
}

.entry .translation {
  font-size: 1.08rem;
}

.entry .translation.pending {
  color: var(--muted);
  font-style: italic;
}

.entry .translation.failed {
  color: var(--live);
}

.settings summary {
  cursor: pointer;
  font-weight: 600;
}

.settings[open] {
  display: grid;
  gap: 0.6rem;
}

.settings[open] summary {
  margin-bottom: 0.4rem;
}

.settings .quiet {
  justify-self: start;
}

@media (max-width: 760px) {
  .op-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}
