@font-face {
  font-family: "HHMono";
  src: url("../fonts/DejaVuSansMono.ttf?v=1") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "HHMono";
  src: url("../fonts/DejaVuSansMono-Bold.ttf?v=1") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ---- theme tokens: dark (default) / light ---- */
:root {
  color-scheme: dark;
  --bg: #121417;
  --fg: #e6e4dd;
  --dim: #a09e95;
  --card: #1a1d21;
  --border: #2d3238;
  --bar-bg: #e6e4dd;
  --bar-fg: #121417;
  --accent: #e6e4dd;
  --on-accent: #121417;
  --ok: #4cc38a;
  --warn: #e0a23b;
  --bad: #e5645a;
  --focus: #7fb4ff;
  --font: "HHMono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f5ee;
  --fg: #1a1c20;
  --dim: #5d6067;
  --card: #fffdf8;
  --border: #d6d2c4;
  --bar-bg: #1a1c20;
  --bar-fg: #f7f5ee;
  --accent: #1a1c20;
  --on-accent: #f7f5ee;
  --ok: #1d8a5a;
  --warn: #9a6200;
  --bad: #b3261e;
  --focus: #1a5fd0;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }
body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: var(--vvh, 100dvh);
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}

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

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

/* ---- buttons ---- */
.btn {
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0.6rem 1rem;
  background: transparent;
  color: var(--fg);
}
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-small { padding: 0.15rem 0.7rem; }

.icon-btn, .text-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font: inherit;
  color: var(--dim);
  background: transparent;
  border: 0;
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  min-height: 32px;
  cursor: pointer;
}
.icon-btn:hover, .text-btn:hover { color: var(--fg); }

/* Show only the icon of the theme you would switch TO. */
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }
:root[data-theme="light"] .icon-moon { display: block; }
:root[data-theme="light"] .icon-sun { display: none; }

/* ---- banners ---- */
.banner {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem 0.75rem;
  padding: 0.45rem 1rem;
  font-size: 0.9rem;
  text-align: center;
}
.banner-upgrade { background: var(--warn); color: #101010; }
.banner-upgrade .btn { color: #101010; border-color: #101010; }
.banner-offline { background: var(--bad); color: #fff; }

/* ---- login ---- */
.login-view {
  position: relative;
  flex: 1;
  display: grid;
  place-items: center;
  padding: 1rem;
  overflow: auto;
}
.login-theme { position: absolute; top: 0.75rem; right: 0.75rem; }
.login-card {
  width: min(100%, 26rem);
  padding: 1.75rem 1.5rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.login-title { margin: 0 0 0.35rem; font-size: 1.35rem; line-height: 1.3; font-weight: 700; }
.login-sub { margin: 0 0 0.75rem; color: var(--dim); font-size: 0.9rem; }
.login-help { margin: 0 0 1.25rem; font-size: 0.9rem; }
.field { margin-bottom: 1rem; }
.field label { display: block; margin-bottom: 0.3rem; font-size: 0.9rem; font-weight: 700; }
.field input {
  width: 100%;
  padding: 0.6rem 0.7rem;
  font: inherit;
  font-size: 1rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.field input:focus-visible { outline-offset: 0; border-color: var(--focus); }
.hint { margin: 0.25rem 0 0; color: var(--dim); font-size: 0.8rem; }
.login-error { margin: 0 0 0.9rem; color: var(--bad); font-size: 0.9rem; }
.login-notice { margin: 0 0 0.9rem; color: var(--dim); font-size: 0.9rem; }
.login-card .btn { width: 100%; }

/* ---- game view ---- */
.game-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.status-bar {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0 1.5rem;
  padding: 0.35rem 1.25rem;
  background: var(--bar-bg);
  color: var(--bar-fg);
  line-height: 1.6;
}
.status-location { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.status-score-moves { white-space: pre; margin-left: auto; }

.terminal-wrap { position: relative; flex: 1; min-height: 0; display: flex; }
.terminal {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.25rem 1.25rem 2rem;
  font-size: 1.0625rem;
  line-height: 1.6;
  user-select: text;
  -webkit-user-select: text;
  outline-offset: -2px;
}
.terminal > * { max-width: 74ch; margin-inline: auto; }
.line {
  margin-block: 0 0.6rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.line-command { margin-bottom: 0.2rem; }
.line-system { color: var(--dim); font-style: italic; }

.live-line { white-space: pre-wrap; overflow-wrap: anywhere; }
.live-line.pending { visibility: hidden; }
.cursor { animation: blink 1.1s steps(1, end) infinite; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .cursor { animation: none; } }

/* ---- mobile command bar (the only input box; < 900px) ---- */
.mobile-form {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.4rem 0.75rem 0.5rem;
  padding: 0 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
}
.mobile-form:focus-within { border-color: var(--focus); }
.mobile-form input {
  flex: 1;
  min-width: 0;
  padding: 0.7rem 0;
  font: inherit;
  font-size: 1rem; /* >=16px: stops iOS zoom-on-focus */
  color: var(--fg);
  background: transparent;
  border: 0;
  outline: none;
}

/* ---- footer ---- */
.footer {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.3rem 1rem calc(0.3rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
  color: var(--dim);
}
.conn { display: inline-flex; align-items: center; gap: 0.5rem; }
.dot { width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--bad); }
.dot[data-state="online"] { background: var(--ok); }
.dot[data-state="connecting"], .dot[data-state="reconnecting"] { background: var(--warn); }
.footer-actions { display: inline-flex; align-items: center; gap: 0.25rem; }

/* ---- responsive: inline typing >= 900px, bottom bar below ---- */
@media (min-width: 900px) {
  .mobile-form { display: none; }
}
@media (max-width: 899px) {
  .live-line { display: none; }
  .terminal { padding: 0.9rem 0.9rem 1rem; font-size: 1rem; }
  .status-bar { padding-inline: 0.9rem; }
}
@media (max-width: 599px) {
  .status-location { flex-basis: 100%; }
  .status-score-moves { margin-left: 0; }
}
