/* ==========================================================================
   ThomasAI

   Flat surfaces, hairline borders, one accent. No beams, no dot grid, no
   grain overlay, no gradient text, no bloom — those read as decoration for
   decoration's sake. Depth comes from three stacked greys and a 1px line;
   colour is spent only where it means something (active tab, primary action,
   focus ring, hover edge).
   ========================================================================== */

:root {
  /* warm near-black, not blue-black — orange sits badly on cool greys */
  --bg:      #0d0b09;
  --panel:   #141110;
  --panel-2: #191514;
  --raise:   #201b18;

  --line:   #272120;
  --line-2: #332b28;

  --ink:   #f2ece5;
  --ink-2: #b0a599;
  --ink-3: #7b7167;

  --or:      #ff8f42;
  --or-lift: #ffab6e;
  --or-deep: #c2621d;
  --or-tint: rgba(255, 143, 66, .10);
  --or-edge: rgba(255, 143, 66, .32);

  --bad: #ff7a6b;

  --r:    9px;
  --r-sm: 7px;
  --top:  54px;
  --shell: 1180px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.55 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

::selection { background: var(--or-deep); color: #fff; }

:focus-visible {
  outline: 2px solid var(--or);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ------------------------------------------------------------------ header */

.top {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--top);
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 22px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.015em;
}

/* one square, one corner cut differently. that is the whole logo. */
.mark {
  width: 15px;
  height: 15px;
  background: var(--or);
  border-radius: 3px 7px 7px 7px;
}

.brand b { font-weight: 600; color: var(--ink-3); }

.tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 100%;
}

/* underline, not a sliding pill. no measuring, no resize handler. */
.tabs a {
  position: relative;
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 13px;
  color: var(--ink-3);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: color .12s;
}

.tabs a:hover { color: var(--ink-2); }
.tabs a.on    { color: var(--ink); }

.tabs a.on::after {
  content: "";
  position: absolute;
  left: 13px;
  right: 13px;
  bottom: -1px;
  height: 2px;
  background: var(--or);
}

.status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--ink-3);
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-3);
}

.status.busy .dot { background: var(--or); animation: pulse 1s ease-in-out infinite; }
.status.bad  .dot { background: var(--bad); }
.status.bad       { color: var(--bad); }

@keyframes pulse { 50% { opacity: .28; } }

.loadbar {
  position: sticky;
  top: var(--top);
  z-index: 39;
  height: 2px;
  /* pulled back out of flow so it overlays instead of shoving the page down —
     otherwise it eats 2px of every full-height pane */
  margin-bottom: -2px;
  background: var(--or);
  transform: scaleX(0);
  transform-origin: left;
  opacity: 0;
  transition: opacity .15s;
}

.loadbar.on {
  opacity: 1;
  animation: crawl 1.6s ease-out infinite;
}

@keyframes crawl {
  0%   { transform: scaleX(0);   }
  70%  { transform: scaleX(.82); }
  100% { transform: scaleX(1); opacity: 0; }
}

/* ------------------------------------------------------------------- panes */

.stage {
  max-width: var(--shell);
  margin: 0 auto;
  padding: 0 22px;
}

.pane { display: none; }
.pane.on { display: block; }

.head { padding: 34px 0 22px; }

.head h1 {
  margin: 0 0 7px;
  font-size: 27px;
  font-weight: 600;
  letter-spacing: -.02em;
}

.head p {
  margin: 0;
  max-width: 62ch;
  color: var(--ink-2);
  font-size: 14px;
  line-height: 1.6;
}

/* ------------------------------------------------------------- form fields */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
  padding-bottom: 18px;
}

.field {
  height: 36px;
  padding: 0 11px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  transition: border-color .12s, background .12s;
}

.field::placeholder { color: var(--ink-3); }

.field:hover { border-color: var(--line-2); }

.field:focus {
  outline: none;
  border-color: var(--or-edge);
  background: var(--panel-2);
}

.grow { flex: 1; min-width: 180px; }

select.field {
  padding-right: 28px;
  cursor: pointer;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
    linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-size: 5px 5px, 5px 5px;
  background-position: right 13px center, right 8px center;
  background-repeat: no-repeat;
}

select.field option { background: var(--panel-2); color: var(--ink); }

input[type="search"]::-webkit-search-cancel-button { filter: invert(.55); }

.hint {
  margin: 0;
  color: var(--ink-3);
  font-size: 12.5px;
}

/* ----------------------------------------------------------------- buttons */

.btn {
  --face: var(--raise);
  --edge: var(--line-2);

  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px;
  background: var(--face);
  border: 1px solid var(--edge);
  border-radius: var(--r-sm);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: background .12s, border-color .12s, transform .06s;
}

.btn:hover:not(:disabled) { border-color: var(--or-edge); }

/* the press. a real 1px of travel, no shadow theatre. */
.btn:active:not(:disabled) { transform: translateY(1px); }

.btn:disabled { opacity: .45; cursor: default; }

.btn svg { display: block; }

.btn-primary {
  --face: var(--or);
  --edge: var(--or-lift);
  color: #2a1405;
  font-weight: 600;
  border-bottom-width: 2px;
  border-bottom-color: var(--or-deep);
}

.btn-primary:hover:not(:disabled) { --face: var(--or-lift); --edge: var(--or-lift); }

.btn-primary:active:not(:disabled) { border-bottom-width: 1px; margin-bottom: 1px; }

.btn-sm { height: 30px; padding: 0 11px; font-size: 13px; }

.btn-ico { width: 36px; padding: 0; }

/* -------------------------------------------------------------- game tiles */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 12px;
  padding-bottom: 56px;
}

.tile {
  padding: 0;
  background: none;
  border: 0;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.tile-art {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  transition: border-color .12s;
}

.tile-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .22s ease;
}

.tile:hover .tile-art     { border-color: var(--or-edge); }
.tile:hover .tile-art img { transform: scale(1.035); }
.tile:active              { transform: translateY(1px); }

.tile-name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 22px 9px 8px;
  /* a flat scrim, not a soft bloom — legibility is the only job here */
  background: linear-gradient(to top, rgba(8, 6, 5, .92), rgba(8, 6, 5, 0));
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tile-tag {
  position: absolute;
  top: 7px;
  left: 7px;
  z-index: 1;
  padding: 2px 6px;
  background: rgba(8, 6, 5, .78);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  color: var(--ink-2);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.skel { pointer-events: none; }

.skel .tile-art {
  background: var(--panel);
  animation: breathe 1.3s ease-in-out infinite;
}

@keyframes breathe { 50% { opacity: .45; } }

/* ------------------------------------------------------------- empty state */

.empty {
  padding: 52px 20px;
  text-align: center;
  color: var(--ink-2);
}

.empty h2 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -.015em;
}

.empty p {
  margin: 0 auto;
  max-width: 46ch;
  font-size: 14px;
  line-height: 1.6;
}

.starters {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 22px;
}

.starter {
  padding: 8px 13px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
  transition: border-color .12s, color .12s;
}

.starter:hover { border-color: var(--or-edge); color: var(--ink); }
.starter:active { transform: translateY(1px); }

/* ------------------------------------------------------------------ player */

.player {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: none;
  grid-template-rows: auto 1fr;
  background: var(--bg);
}

.player.on { display: grid; }

.player-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--top);
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}

.player-bar h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.by {
  color: var(--ink-3);
  font-size: 13px;
  white-space: nowrap;
}

.sp {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.player-frame {
  position: relative;
  background: #000;
}

.player-frame iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.player-load {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  background: var(--bg);
  color: var(--ink-3);
  font-size: 13px;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--line-2);
  border-top-color: var(--or);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* -------------------------------------------------------------------- chat */

.chat {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--top));
  padding: 18px 0 12px;
}

.thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-2) transparent;
}

.thread::-webkit-scrollbar { width: 9px; }
.thread::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border: 3px solid var(--bg);
  border-radius: 6px;
}

.msg {
  display: flex;
  gap: 11px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.msg:last-child { border-bottom: 0; }

.av {
  flex: none;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink-3);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .02em;
}

.msg.me .av {
  background: var(--or-tint);
  border-color: var(--or-edge);
  color: var(--or-lift);
}

.bubble {
  min-width: 0;
  flex: 1;
  padding-top: 4px;
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--ink);
  overflow-wrap: anywhere;
}

/* a caret while tokens are still arriving */
.bubble.live::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--or);
  animation: blink .9s steps(1) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

.att {
  max-width: 260px;
  max-height: 200px;
  margin: 0 8px 8px 0;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  display: inline-block;
  vertical-align: top;
}

/* --- markdown inside a reply --- */

.bubble p  { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }

.bubble h1, .bubble h2, .bubble h3 {
  margin: 16px 0 8px;
  font-weight: 600;
  letter-spacing: -.01em;
  line-height: 1.35;
}

.bubble h1 { font-size: 19px; }
.bubble h2 { font-size: 17px; }
.bubble h3 { font-size: 15.5px; }
.bubble :is(h1, h2, h3):first-child { margin-top: 0; }

.bubble ul, .bubble ol { margin: 0 0 10px; padding-left: 21px; }
.bubble li { margin-bottom: 4px; }

.bubble a { color: var(--or-lift); text-decoration: underline; text-underline-offset: 2px; }
.bubble a:hover { color: var(--or); }

.bubble strong { font-weight: 600; }

.bubble code {
  padding: 1.5px 5px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: .875em;
  color: var(--or-lift);
}

.bubble pre {
  margin: 0 0 10px;
  padding: 12px 13px;
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}

.bubble pre code {
  padding: 0;
  background: none;
  border: 0;
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.6;
}

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

.composer {
  flex: none;
  margin-top: 12px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  transition: border-color .12s;
}

.composer:focus-within { border-color: var(--line-2); }

.composer textarea {
  width: 100%;
  max-height: 190px;
  padding: 4px 4px 8px;
  background: none;
  border: 0;
  resize: none;
  color: var(--ink);
  font: inherit;
  font-size: 14.5px;
  line-height: 1.55;
}

.composer textarea:focus { outline: none; }
.composer textarea::placeholder { color: var(--ink-3); }

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

.composer-row .field { max-width: 320px; }

.thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding-bottom: 9px;
}

/* an author `display` beats the UA sheet's [hidden] rule, so the attribute the
   script toggles has to be honoured explicitly or the strip never collapses */
.thumbs[hidden] { display: none; }

.thumb { position: relative; }

.thumb img {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  display: block;
}

.thumb button {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  background: var(--raise);
  border: 1px solid var(--line-2);
  border-radius: 50%;
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

.thumb button:hover { border-color: var(--or-edge); color: var(--ink); }

.kbdline {
  flex: none;
  margin: 8px 2px 0;
  text-align: right;
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  font-family: inherit;
  font-size: 11px;
  color: var(--ink-2);
}

/* ------------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 120;
  max-width: min(440px, calc(100vw - 32px));
  padding: 10px 15px;
  background: var(--raise);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  color: var(--ink);
  font-size: 13.5px;
  transform: translate(-50%, 14px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s, transform .16s;
}

.toast.on {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ------------------------------------------------------------------ narrow */

@media (max-width: 720px) {
  .top   { gap: 12px; padding: 0 14px; }
  .stage { padding: 0 14px; }
  .status { display: none; }

  .head { padding: 24px 0 18px; }
  .head h1 { font-size: 23px; }

  .tiles { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; }

  .grow { min-width: 120px; }
  .composer-row .field { max-width: none; }
  .kbdline { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
