:root {
  color-scheme: light dark;
  --page-bg: #eef2f7;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --panel-strong: #e7edf5;
  --text: #15202e;
  --muted: #536176;
  --border: #bac5d4;
  --accent: #005f99;
  --accent-strong: #00456f;
  --accent-text: #ffffff;
  --secondary: #4d596b;
  --success: #0f766e;
  --danger: #b42318;
  --focus: #0a84ff;
  --menu-active: #d9ecfb;
  --menu-readonly: #eef1f5;
  --shadow: rgba(15, 23, 42, 0.08);
  --radius: 8px;
  --control-min: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page-bg: #111821;
    --panel: #17202d;
    --panel-soft: #101722;
    --panel-strong: #223047;
    --text: #f1f5f9;
    --muted: #b6c2d2;
    --border: #41516a;
    --accent: #5fb3e6;
    --accent-strong: #90cdf4;
    --accent-text: #08111c;
    --secondary: #6b7a91;
    --success: #5eead4;
    --danger: #ff9b90;
    --focus: #ffd166;
    --menu-active: #244363;
    --menu-readonly: #202938;
    --shadow: rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--page-bg);
}

[hidden],
.hidden {
  display: none !important;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: clamp(1.4rem, 2.5vw, 1.9rem);
  line-height: 1.2;
}

h2 {
  margin-bottom: 8px;
  font-size: 1.15rem;
  line-height: 1.25;
}

h3 {
  margin-bottom: 8px;
  font-size: 1.05rem;
  line-height: 1.25;
}

button,
input,
select,
textarea {
  min-height: var(--control-min);
  font: inherit;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
}

input,
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--panel-soft);
}

button {
  padding: 8px 12px;
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--accent-strong);
}

button.secondary {
  color: #ffffff;
  background: var(--secondary);
  border-color: var(--secondary);
}

button:disabled,
[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.68;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
#menu-list:focus-visible,
.menu-item:focus-visible,
.menu-item-touch:focus-visible,
.actions-item-btn:focus-visible,
.history-log:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 2px 10px var(--shadow);
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

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

.status.error {
  color: var(--danger);
}

.eyebrow {
  margin-bottom: 2px;
  color: var(--success);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.auth-card {
  width: min(620px, 100%);
  padding: 20px;
}

.brand-block {
  margin-bottom: 16px;
}

.auth-toolbar {
  justify-content: space-between;
  padding: 10px;
  margin-bottom: 12px;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.compact-field {
  display: grid;
  gap: 4px;
  min-width: min(220px, 100%);
}

.saved-session {
  padding: 10px;
  margin-bottom: 12px;
  background: var(--panel-strong);
  border-radius: var(--radius);
}

.auth-nav {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.auth-nav-btn {
  color: var(--text);
  background: var(--panel-soft);
  border-color: var(--border);
}

.auth-nav-btn.active {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}

.auth-panel form {
  display: grid;
  gap: 8px;
}

.check-row {
  width: fit-content;
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.check-row input {
  width: auto;
  min-height: auto;
}

.game-screen {
  display: grid;
  gap: 12px;
}

.audio-panel {
  padding: 10px 12px;
}

.volume-controls {
  align-items: end;
}

.volume-controls label {
  display: grid;
  gap: 2px;
  min-width: 120px;
  color: var(--muted);
}

.volume-controls output {
  color: var(--text);
  font-weight: 700;
}

.volume-controls input[type="range"] {
  width: min(170px, 42vw);
}

.game-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.95fr) minmax(420px, 1.35fr);
  gap: 12px;
}

.menu-panel,
.history-panel,
.chat-panel,
.shortcuts-panel {
  padding: 12px;
}

.panel-heading,
.history-header {
  justify-content: space-between;
  margin-bottom: 8px;
}

.menu-list {
  --grid-cols: 1;
  min-height: 280px;
  max-height: 56vh;
  padding: 0;
  margin: 0;
  overflow: auto;
  list-style: none;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  -webkit-overflow-scrolling: touch;
}

.menu-list.grid-mode {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols), minmax(0, 1fr));
  align-content: start;
}

.menu-item {
  min-height: var(--control-min);
  padding: 9px 10px;
  color: var(--text);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.grid-mode .menu-item {
  border-right: 1px solid var(--border);
}

.menu-item:last-child {
  border-bottom: 0;
}

.menu-item[aria-disabled="true"] {
  background: var(--menu-readonly);
  opacity: 1;
}

.menu-item.active {
  background: var(--menu-active);
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.menu-item-touch {
  width: 100%;
  min-height: var(--control-min);
  padding: 9px 10px;
  color: var(--text);
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(10, 132, 255, 0.22);
}

.menu-item-touch:hover:not(:disabled) {
  background: transparent;
}

.menu-item-touch:active,
.actions-item-btn:active {
  background: var(--menu-active);
}

.actions-item-btn {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(10, 132, 255, 0.22);
}

.inline-input {
  display: grid;
  gap: 8px;
  padding: 10px;
  margin-top: 10px;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.history-header {
  display: flex;
  gap: 8px;
  align-items: center;
}

.history-toggle-title {
  padding: 0;
  color: var(--text);
  text-align: left;
  background: transparent;
  border: 0;
}

.history-toggle-title:hover:not(:disabled) {
  background: transparent;
}

.history {
  width: 100%;
  min-height: 360px;
  height: 56vh;
  resize: vertical;
  white-space: pre-wrap;
}

.history-log {
  min-height: 360px;
  height: 56vh;
  padding: 10px;
  overflow: auto;
  color: var(--text);
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  -webkit-overflow-scrolling: touch;
}

.history-line {
  margin: 0 0 6px;
  white-space: pre-wrap;
}

.chat-panel,
.shortcuts-panel {
  display: grid;
  gap: 10px;
}

.chat-form {
  display: grid;
  gap: 6px;
}

.chat-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
}

.voice-card {
  padding: 10px;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.recaptcha-hidden .grecaptcha-badge {
  visibility: hidden;
}

@media (max-width: 920px) {
  .app-shell {
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .game-grid,
  .chat-row {
    grid-template-columns: 1fr;
  }

  .auth-card,
  .menu-panel,
  .history-panel,
  .chat-panel,
  .shortcuts-panel {
    padding: 10px;
  }

  .auth-nav {
    grid-template-columns: 1fr;
  }

  .volume-controls {
    align-items: stretch;
  }

  .volume-controls label,
  .volume-controls input[type="range"] {
    width: 100%;
  }

  .menu-list {
    max-height: 45vh;
  }

  .history {
    display: none;
  }

  .history-log {
    display: block;
    min-height: 180px;
    height: 32vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}
