:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #0f1318;
  --ink: #d8e1ee;
  --muted: #8ea3bf;
  --accent: #8cffd2;
  --danger: #ff7b7b;
  --border: rgba(216, 225, 238, 0.14);
  --shadow: rgba(0, 0, 0, 0.45);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: radial-gradient(1200px 800px at 20% 0%, #101827 0%, var(--bg) 55%);
  color: var(--ink);
  font-family: var(--mono);
  display: grid;
  place-items: center;
  padding: 18px;
  /* Stop iOS Safari from auto-bumping our font-size in portrait orientation. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.shell {
  width: min(920px, 100%);
  height: min(740px, 100dvh);
  border: 1px solid var(--border);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 35%),
    var(--panel);
  box-shadow: 0 20px 60px var(--shadow);
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  letter-spacing: 0.03em;
}

.meta {
  display: flex;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
}

.screen {
  overflow: auto;
  padding: 16px;
}

.transcript {
  display: flex;
  flex-direction: column;
  gap: 10px;
  line-height: 1.45;
  font-size: 14px;
}

.line {
  white-space: pre-wrap;
  word-break: break-word;
}

.line.user {
  color: var(--accent);
}

.line.system {
  color: var(--muted);
}

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

.prompt {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

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

.commandInput {
  width: 100%;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--ink);
  padding: 10px 12px;
  border-radius: 10px;
  outline: none;
  font-family: var(--mono);
  font-size: 14px;
}

.commandInput:focus {
  border-color: rgba(140, 255, 210, 0.6);
  box-shadow: 0 0 0 3px rgba(140, 255, 210, 0.12);
}

.sendBtn {
  border: 1px solid var(--border);
  background: rgba(140, 255, 210, 0.12);
  color: var(--ink);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--mono);
}

.sendBtn:hover {
  border-color: rgba(140, 255, 210, 0.5);
  background: rgba(140, 255, 210, 0.16);
}

.footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.footerBtn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 13px;
}

.footerBtn:hover {
  border-color: rgba(216, 225, 238, 0.3);
  background: rgba(255, 255, 255, 0.06);
}

/* ===================================================================== */
/*  Mobile / responsive                                                  */
/* ===================================================================== */

/* Tablet — let the shell stretch a bit before phone styles kick in. */
@media (max-width: 900px) {
  body { padding: 10px; }
  .shell {
    width: 100%;
    height: min(820px, calc(100dvh - 20px));
  }
}

/* Phone — lock the shell to the visible viewport so the whole game fits
   in portrait without scrolling, no zoom-in. Use stable `100svh` (small-
   viewport-height) instead of `100dvh` so the shell DOES NOT shrink when
   the iOS virtual keyboard appears — the keyboard slides over instead. */
@media (max-width: 720px) {
  /* Belt-and-braces: any input/textarea/select renders ≥16px on phone so
     iOS Safari never auto-zooms on focus, regardless of what's added later. */
  input, textarea, select { font-size: 16px !important; }

  html, body {
    height: 100%;
    height: 100svh;          /* stable across keyboard show/hide */
    overflow: hidden;
  }
  body {
    padding: 0;
    place-items: stretch;
    background: var(--bg);   /* skip the radial gradient on phone — flat is faster + less artifacty */
  }
  .shell {
    width: 100vw;
    max-width: 100vw;
    /* With viewport meta `interactive-widget=overlays-content`, the keyboard
       floats over the page without resizing the viewport. We then subtract
       `env(keyboard-inset-height)` so the shell shrinks from the bottom and
       the prompt input stays visible above the keyboard. Falls back to 0
       when no keyboard is showing or when the browser doesn't support it. */
    height: calc(100svh - env(keyboard-inset-height, 0px));
    max-height: calc(100svh - env(keyboard-inset-height, 0px));
    border: none;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
    grid-template-rows: auto 1fr auto auto;
    /* Smooth out the resize when the keyboard slides in/out. */
    transition: height 0.18s ease;
  }

  /* Topbar — single tight row: brand left, score chips right (no labels). */
  .topbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 8px 10px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .topbar::-webkit-scrollbar { display: none; }
  .brand {
    font-size: 14px;
    flex: 0 0 auto;
    white-space: nowrap;
  }
  .meta {
    flex: 1 1 auto;
    justify-content: flex-end;
    gap: 8px;
    font-size: 11px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .meta::-webkit-scrollbar { display: none; }
  .meta span {
    white-space: nowrap;
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
  }

  .screen {
    padding: 10px 12px;
    -webkit-overflow-scrolling: touch;
  }
  .transcript {
    font-size: 13.5px;
    line-height: 1.4;
    gap: 8px;
  }

  /* Prompt row */
  .prompt {
    grid-template-columns: auto 1fr auto;
    gap: 8px;
    padding: 8px 10px;
  }
  .commandInput {
    font-size: 16px;       /* iOS no-zoom on focus */
    padding: 10px 12px;
    border-radius: 8px;
  }
  .sendBtn {
    font-size: 13px;
    padding: 10px 12px;
    min-height: 40px;
    border-radius: 8px;
  }

  /* Footer: 3-col grid x 2 rows for the 6 quick-action buttons. */
  .footer {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    padding: 8px 10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }
  .footerBtn {
    font-size: 12.5px;
    padding: 10px 4px;
    min-height: 40px;
    border-radius: 6px;
    text-align: center;
  }
}

/* Tiny phones — tighten further. */
@media (max-width: 380px) {
  .topbar .brand { font-size: 13px; }
  .meta { font-size: 10.5px; gap: 5px; }
  .meta span { padding: 2px 5px; }
  .transcript { font-size: 13px; }
  .footerBtn { font-size: 11.5px; padding: 8px 2px; }
}

/* Landscape phone — keep the layout, just give the meta more room. */
@media (max-width: 900px) and (orientation: landscape) {
  .footer { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
