/* Semantic colors mirror the Android app (values/colors.xml + values-night). */
:root {
  --background: #ffffff;
  --surface: #ffffff;
  --status-bar: #f5f5f5;
  --text-primary: #000000;
  --text-muted: #757575;
  --accent: #018786;
  --red: #ff0000;
  --button-bg: #f0f0f0;
  --button-border: #d8d8d8;
  --scrim: rgba(0, 0, 0, 0.45);
}

/* Dark palette: applied when the system prefers dark AND the user hasn't forced light. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --background: #121212;
    --surface: #1e1e1e;
    --status-bar: #1e1e1e;
    --text-primary: #ececec;
    --text-muted: #9e9e9e;
    --accent: #03dac5;
    --button-bg: #2a2a2a;
    --button-border: #3a3a3a;
    --scrim: rgba(0, 0, 0, 0.6);
  }
}

/* Explicit overrides chosen in Settings. */
:root[data-theme="light"] {
  --background: #ffffff;
  --surface: #ffffff;
  --status-bar: #f5f5f5;
  --text-primary: #000000;
  --text-muted: #757575;
  --accent: #018786;
  --button-bg: #f0f0f0;
  --button-border: #d8d8d8;
  --scrim: rgba(0, 0, 0, 0.45);
}
:root[data-theme="dark"] {
  --background: #121212;
  --surface: #1e1e1e;
  --status-bar: #1e1e1e;
  --text-primary: #ececec;
  --text-muted: #9e9e9e;
  --accent: #03dac5;
  --button-bg: #2a2a2a;
  --button-border: #3a3a3a;
  --scrim: rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--background);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Transcript: grows to fill, scrolls, pins newest content to the bottom. */
#transcript {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  margin: 6px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  scrollbar-width: none;
}
#transcript::-webkit-scrollbar {
  display: none;
}
/* Pins content to the bottom (like the Android gravity="bottom") while staying
   scrollable once it overflows. */
#transcriptInner {
  margin-top: auto;
  font-size: var(--transcript-size, 14px);
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  -webkit-user-select: text;
  user-select: text;
}

.line {
  color: var(--text-primary);
}
.line.muted {
  color: var(--text-muted);
}
.line.accent {
  color: var(--accent);
}
.line.error {
  color: var(--red);
}

/* Bottom button row, mirroring activity_main.xml weights. */
#buttons {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 16px;
  flex: 0 0 auto;
}

#buttons button {
  flex: 1 1 0;
  height: 50px;
  min-width: 0;
  border: 1px solid var(--button-border);
  border-radius: 8px;
  background: var(--button-bg);
  color: var(--text-primary);
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#buttons button.wide {
  flex-grow: 1.25;
}
#buttons button:active {
  background: var(--button-border);
}
#recordButton {
  color: var(--red);
}
#translateButton,
#speakAloudButton {
  color: var(--accent);
}

.hidden {
  display: none !important;
}

/* Overlays (settings + API key). */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

#settingsSheet,
#apiKeySheet {
  background: var(--surface);
  color: var(--text-primary);
  border-radius: 12px;
  padding: 20px 24px;
  min-width: 240px;
  max-width: 88vw;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

.settings-group {
  display: flex;
  flex-direction: column;
}

.settings-item {
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  font-size: 15px;
  padding: 12px 0;
  cursor: pointer;
  color: var(--text-primary);
  white-space: pre;
}
.settings-item.selected {
  color: var(--accent);
}

.sheet-title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 14px;
}

#apiKeyInput {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid var(--button-border);
  border-radius: 8px;
  background: var(--background);
  color: var(--text-primary);
}

.sheet-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}
.sheet-actions .spacer {
  flex: 1;
}
.sheet-actions a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
}
.text-button {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 15px;
  padding: 6px 4px;
  cursor: pointer;
}
.text-button.accent {
  color: var(--accent);
  font-weight: 600;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 20;
  max-width: 80vw;
  text-align: center;
}
