/*
 * Mobsh web terminal chrome.
 *
 * The terminal owns the screen; everything else is a restrained full-width
 * band in the charcoal/paper palette from docs/design.md. One typeface — the
 * bundled Nerd Font — for cells, labels, and controls alike: this is an
 * instrument, not a site. Chrome follows the OS light/dark preference; the
 * cell grid keeps its own fixed terminal theme.
 */

@font-face {
  font-family: 'MobshTerm';
  font-style: normal;
  font-weight: 400;
  src: url('fonts/JetBrainsMonoNerdFontMono-Regular.ttf') format('truetype');
  font-display: block;
}
@font-face {
  font-family: 'MobshTerm';
  font-style: normal;
  font-weight: 700;
  src: url('fonts/JetBrainsMonoNerdFontMono-Bold.ttf') format('truetype');
  font-display: block;
}
@font-face {
  font-family: 'MobshTerm';
  font-style: italic;
  font-weight: 400;
  src: url('fonts/JetBrainsMonoNerdFontMono-Italic.ttf') format('truetype');
  font-display: block;
}
@font-face {
  font-family: 'MobshTerm';
  font-style: italic;
  font-weight: 700;
  src: url('fonts/JetBrainsMonoNerdFontMono-BoldItalic.ttf') format('truetype');
  font-display: block;
}

:root {
  --bg: #141414;
  --band: #1b1b19;
  --ink: #e8e6e1;
  --muted: #8a8781;
  --line: #2c2c29;
  --key: #1f1f1d;
  --key-down: #35352f;
  --green: #67c587;
  --amber: #f2b84b;
  --red: #e06c75;
  /* Kept in sync with the visual viewport by app.js so the key strip stays
     above the software keyboard. */
  --vvh: 100dvh;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f0ea;
    --band: #e9e6de;
    --ink: #21211e;
    --muted: #6d6a62;
    --line: #d6d2c8;
    --key: #e9e6de;
    --key-down: #d6d2c8;
    --green: #2c7a4b;
    --amber: #9a6b0a;
    --red: #b3423e;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'MobshTerm', ui-monospace, Menlo, monospace;
  font-size: 14px;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  background: var(--key);
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}
button:active { background: var(--key-down); }

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

/* --- login ---------------------------------------------------------------- */

/* Both views set display, so the hidden attribute needs explicit backing. */
.login[hidden] { display: none; }

.login {
  height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

.login-form {
  width: 100%;
  max-width: 20rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.wordmark {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.02em;
}

/* The signature mark: a steady terminal block cursor after the name. */
.cursor-block {
  display: inline-block;
  width: 0.55em;
  height: 1em;
  margin-left: 0.15em;
  vertical-align: text-bottom;
  background: var(--green);
}
@media (prefers-reduced-motion: no-preference) {
  .cursor-block { animation: blink 1.2s step-end infinite; }
  @keyframes blink { 50% { opacity: 0; } }
}

.login-sub {
  margin: 0 0 0.4rem;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field-label {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: lowercase;
}
.field input {
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 0.7rem;
  min-height: 44px;
}
.field input:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }

#login-submit {
  min-height: 44px;
  margin-top: 0.3rem;
  font-weight: 700;
}

.login-error {
  min-height: 1.3em;
  margin: 0;
  color: var(--red);
  font-size: 0.86rem;
}

/* --- terminal view -------------------------------------------------------- */

.app {
  height: var(--vvh);
  display: flex;
  flex-direction: column;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
.app[hidden] { display: none; }

.band {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 38px;
  padding: 0 0.75rem;
  padding-top: env(safe-area-inset-top);
  background: var(--band);
  border-bottom: 1px solid var(--line);
  font-size: 0.82rem;
}

.dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.dot[data-state="connected"] { background: var(--green); }
.dot[data-state="connecting"],
.dot[data-state="reconnecting"] { background: var(--amber); }
.dot[data-state="dead"],
.dot[data-state="ended"] { background: var(--red); }

.band-text { color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.band-spacer { flex: 1; }
.band-user { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.band-btn {
  flex: none;
  min-height: 30px;
  padding: 0 0.7rem;
  font-size: 0.82rem;
}

.screen {
  flex: 1;
  min-height: 0;
  position: relative;
  background: #141414; /* terminal theme background, independent of chrome */
  padding: 2px 0 0 4px;
}
.screen .xterm { height: 100%; }
.xterm-viewport::-webkit-scrollbar { width: 0; height: 0; }

/* --- composer ------------------------------------------------------------- */

.composer {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  background: var(--band);
  border-top: 1px solid var(--line);
}
.composer[hidden] { display: none; }

.composer textarea {
  font: inherit;
  font-size: 16px; /* below 16px iOS zooms the page on focus */
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.5rem 0.6rem;
  resize: none;
  height: 6.4rem;
}

.composer-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.composer-actions button {
  min-height: 44px;
  padding: 0 1rem;
}
.composer-actions .ghost { background: transparent; }
#composer-send { font-weight: 700; }

/* --- extended-key strip --------------------------------------------------- */

.keybar {
  flex: none;
  display: flex;
  align-items: stretch;
  background: var(--band);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.keys {
  flex: 1;
  display: flex;
  gap: 4px;
  padding: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.keys::-webkit-scrollbar { display: none; }

.keys button {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  padding: 0 0.55rem;
  font-size: 0.86rem;
  color: var(--ink);
}

.keys button[aria-pressed="true"] {
  background: var(--green);
  border-color: var(--green);
  color: #141414;
  font-weight: 700;
}

.keybar-toggle {
  flex: none;
  min-width: 48px;
  min-height: 44px;
  margin: 4px;
  margin-left: 0;
  border-left: 1px solid var(--line);
  font-weight: 700;
}
.keybar-toggle[aria-expanded="true"] {
  background: var(--key-down);
}

/* Desktop: a pointer does not need 44px targets, and the strip can shrink so
   the grid gets the rows back. */
@media (hover: hover) and (pointer: fine) {
  .keys button, .keybar-toggle { min-height: 30px; min-width: 34px; }
  .composer-actions button { min-height: 32px; }
  .band { min-height: 32px; }
}
