/* 4AM Tiles — game styles. Dark "4am tea-house" palette, pixel-flavored chrome.
   DOM-rendered tiles (PRD §5.4). No webfonts, no images: everything is CSS/SVG
   so first load stays tiny. */

:root {
  --bg: #14121f;
  --bg-2: #1c1930;
  --panel: #241f3d;
  --panel-2: #2d2749;
  --line: #3b3463;
  --ink: #efe9da;
  --ink-dim: #a49bc4;
  --amber: #ffb454;
  --amber-deep: #e08a2d;
  --pink: #ff5c8a;
  --teal: #4ecdc4;
  --tile-face: #f6efdc;
  --tile-edge: #cbb88f;
  --tile-back: #5b4a9e;
  --dots: #2274a5;
  --bamboo: #3e8948;
  --chars: #c1121f;
  --wind: #3d348b;
  --dragon-red: #c1121f;
  --dragon-green: #3e8948;
  --dragon-white: #6b7280;
  --flower: #d9578d;
  --shadow: 0 4px 0 rgba(0, 0, 0, 0.45);
  font-size: 16px;
}

* { box-sizing: border-box; }

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

body {
  background:
    radial-gradient(1000px 600px at 50% 42%, rgba(255, 180, 84, 0.10), transparent 62%),
    linear-gradient(var(--bg-2), var(--bg));
  color: var(--ink);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 2px solid var(--line);
  background: rgba(20, 18, 31, 0.85);
  /* Stays above the modal overlay so New Game is always reachable. */
  position: relative;
  z-index: 50;
}

.brand {
  font-weight: 900;
  font-size: 1.15rem;
  letter-spacing: 0.14em;
  color: var(--amber);
  text-decoration: none;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.6);
}
.brand span { color: var(--ink); }

.topbar-right { display: flex; gap: 8px; align-items: center; }

.wall-pill {
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  color: var(--ink-dim);
  background: var(--panel);
  border: 2px solid var(--line);
  padding: 6px 10px;
}
.wall-pill b { color: var(--amber); font-size: 0.85rem; }

.chip {
  font: inherit;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--bg);
  background: var(--amber);
  border: 0;
  border-bottom: 3px solid var(--amber-deep);
  padding: 7px 12px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.chip:active { transform: translateY(2px); border-bottom-width: 1px; }
.chip-ghost { background: var(--panel-2); color: var(--ink); border-bottom-color: var(--line); }

/* ---------- Table layout ---------- */

.table {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template:
    "left top   right" auto
    "left center right" 1fr
    "you  you   you" auto
    / minmax(150px, 1fr) minmax(0, 2.4fr) minmax(150px, 1fr);
  gap: 10px;
  padding: 12px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.seat-top { grid-area: top; }
.seat-left { grid-area: left; align-self: center; }
.seat-right { grid-area: right; align-self: center; }
.center { grid-area: center; }
.you { grid-area: you; }

/* ---------- Bot seats ---------- */

.seat .bot-card {
  background: var(--panel);
  border: 2px solid var(--line);
  box-shadow: var(--shadow);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.25s, box-shadow 0.25s;
}
.seat.active .bot-card {
  border-color: var(--amber);
  box-shadow: 0 0 0 2px rgba(255, 180, 84, 0.25), 0 0 22px rgba(255, 180, 84, 0.28);
}

.bot-id { display: flex; gap: 10px; align-items: center; }
.bot-avatar {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  image-rendering: pixelated;
  background: var(--bg);
  border: 2px solid var(--line);
}
.seat.active .bot-avatar { border-color: var(--amber); }
.bot-name { font-weight: 800; font-size: 0.85rem; letter-spacing: 0.06em; }
.bot-style { font-size: 0.62rem; color: var(--ink-dim); letter-spacing: 0.08em; text-transform: uppercase; }

.bot-hand { display: flex; gap: 2px; flex-wrap: wrap; }
.bot-status { font-size: 0.66rem; color: var(--ink-dim); min-height: 0.9em; }
.bot-status .thinking { color: var(--amber); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.35; } }

/* ---------- Center: river + banner ---------- */

.center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background:
    radial-gradient(closest-side, rgba(255, 180, 84, 0.07), transparent),
    var(--bg-2);
  border: 2px solid var(--line);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.45);
  padding: 12px;
  min-height: 0;
  overflow: hidden;
}

.banner {
  min-height: 1.4em;
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.12em;
  color: var(--amber);
  text-transform: uppercase;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.6);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s, transform 0.2s;
}
.banner.show { opacity: 1; transform: none; }
.banner.big { font-size: 1.3rem; color: var(--pink); }

.river {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  justify-content: center;
  align-content: flex-start;
  overflow-y: auto;
  max-width: 100%;
}

/* ---------- Tiles ---------- */

.tile {
  position: relative;
  width: 44px;
  height: 60px;
  background: linear-gradient(var(--tile-face), #e9dfc2);
  border: 2px solid var(--tile-edge);
  border-bottom-width: 5px;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  color: var(--bg);
  flex: 0 0 auto;
}
.tile .tv { font-weight: 900; font-size: 1.05rem; line-height: 1; }
.tile .ts { font-size: 0.78rem; line-height: 1; }
.tile.dots .ts, .tile.dots .tv { color: var(--dots); }
.tile.bamboo .ts, .tile.bamboo .tv { color: var(--bamboo); }
.tile.chars .ts, .tile.chars .tv { color: var(--chars); }
.tile.wind .tv { color: var(--wind); font-size: 1.25rem; }
.tile.wind .ts { color: var(--ink-dim); font-size: 0.58rem; letter-spacing: 0.08em; }
.tile.dragon .tv { font-size: 1.25rem; }
.tile.dragon-red .tv { color: var(--dragon-red); }
.tile.dragon-green .tv { color: var(--dragon-green); }
.tile.dragon-white .tv { color: var(--dragon-white); }
.tile.flower { border-color: var(--flower); }
.tile.flower .tv { color: var(--flower); }
.tile.flower .ts { color: var(--flower); font-size: 0.62rem; }

.tile.small { width: 30px; height: 41px; border-bottom-width: 4px; border-radius: 3px; }
.tile.small .tv { font-size: 0.74rem; }
.tile.small .ts { font-size: 0.56rem; }
.tile.small.wind .tv, .tile.small.dragon .tv { font-size: 0.85rem; }

.tile.back {
  background: linear-gradient(160deg, var(--tile-back), #463a7c);
  border-color: #362d63;
}
.tile.back::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 2px dotted rgba(255, 255, 255, 0.28);
  border-radius: 2px;
}
.tile.mini { width: 16px; height: 24px; border-width: 1px; border-bottom-width: 3px; }
.tile.mini.back::after { inset: 2px; border-width: 1px; }

.tile.latest { outline: 3px solid var(--pink); outline-offset: 1px; animation: pop 0.25s ease-out; }
@keyframes pop { from { transform: scale(0.6); } }

/* ---------- Player area ---------- */

.you {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--panel);
  border: 2px solid var(--line);
  box-shadow: var(--shadow);
  padding: 10px 12px;
  transition: border-color 0.25s, box-shadow 0.25s;
}
.you.active {
  border-color: var(--amber);
  box-shadow: 0 0 0 2px rgba(255, 180, 84, 0.25), 0 0 22px rgba(255, 180, 84, 0.28);
}

.you-info { display: flex; gap: 14px; min-height: 26px; align-items: center; flex-wrap: wrap; }
.flowers-row, .melds-row { display: flex; gap: 3px; align-items: center; }
.melds-row .meld { display: flex; gap: 2px; padding: 2px 4px; background: var(--bg-2); border: 1px solid var(--line); }
.row-label { font-size: 0.6rem; letter-spacing: 0.1em; color: var(--ink-dim); margin-right: 4px; }

.hand {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: center;
  padding-top: 6px;
}
.hand .tile { cursor: pointer; transition: transform 0.12s; touch-action: manipulation; }
.hand .tile:hover { transform: translateY(-5px); }
.hand .tile.selected {
  transform: translateY(-12px);
  outline: 3px solid var(--amber);
  outline-offset: 1px;
}
.hand .tile.drawn { box-shadow: 0 0 0 2px var(--teal); margin-left: 10px; }
.hand.locked .tile { cursor: default; opacity: 0.92; }
.hand.locked .tile:hover { transform: none; }

.action-bar {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  min-height: 40px;
  align-items: center;
}
.btn {
  font: inherit;
  font-weight: 900;
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 10px 18px;
  cursor: pointer;
  border: 0;
  border-bottom: 4px solid rgba(0, 0, 0, 0.4);
  color: var(--bg);
  background: var(--amber);
  box-shadow: var(--shadow);
  touch-action: manipulation;
}
.btn:active { transform: translateY(2px); border-bottom-width: 2px; }
.btn.win { background: var(--pink); color: #fff; animation: pulse 0.9s ease-in-out infinite; }
@keyframes pulse { 50% { filter: brightness(1.25); } }
.btn.pass { background: var(--panel-2); color: var(--ink); }
.btn.ghost { background: var(--panel-2); color: var(--ink); font-weight: 600; }
.action-hint { font-size: 0.7rem; color: var(--ink-dim); width: 100%; text-align: center; }

/* ---------- Log ---------- */

.log-toggle {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 30;
  font: inherit;
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  padding: 8px 12px;
  background: var(--panel-2);
  color: var(--ink-dim);
  border: 2px solid var(--line);
  cursor: pointer;
}

.log-panel {
  position: fixed;
  right: 12px;
  bottom: 54px;
  z-index: 30;
  width: min(320px, calc(100vw - 24px));
  max-height: 46vh;
  background: var(--panel);
  border: 2px solid var(--line);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.log-panel[hidden] { display: none; }
.log-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 2px solid var(--line);
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  color: var(--ink-dim);
}
.log { overflow-y: auto; padding: 8px 10px; font-size: 0.72rem; line-height: 1.6; color: var(--ink-dim); }
.log p { margin: 0; }
.log p:last-child { color: var(--ink); }

/* ---------- Overlay (end screen / choices) ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(12, 10, 22, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.overlay[hidden] { display: none; }

.modal {
  background: var(--panel);
  border: 3px solid var(--amber);
  box-shadow: 0 0 40px rgba(255, 180, 84, 0.25), var(--shadow);
  padding: 24px;
  max-width: 460px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  text-align: center;
}
.modal h2 {
  margin: 0 0 4px;
  font-size: 1.5rem;
  letter-spacing: 0.14em;
  color: var(--amber);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.6);
}
.modal h2.lose { color: var(--ink-dim); }
.modal h2.win-you { color: var(--pink); }
.modal .sub { color: var(--ink-dim); font-size: 0.78rem; margin-bottom: 14px; }
.modal .winning-hand { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; margin: 12px 0; }
.score-table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.78rem; }
.score-table td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.score-table td:last-child { text-align: right; color: var(--amber); font-weight: 800; }
.score-table tr.total td { border-top: 2px solid var(--amber); border-bottom: 0; font-weight: 900; color: var(--ink); }
.modal .btn { margin-top: 10px; }
.chow-options { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.chow-option { display: flex; gap: 3px; padding: 6px; background: var(--bg-2); border: 2px solid var(--line); cursor: pointer; }
.chow-option:hover { border-color: var(--amber); }

/* ---------- Mobile ---------- */

@media (max-width: 760px) {
  :root { font-size: 15px; }
  body { overflow-y: auto; }

  /* Bots collapse into one horizontal strip of three cards. */
  .table {
    grid-template:
      "left top right" auto
      "center center center" 1fr
      "you you you" auto
      / 1fr 1fr 1fr;
    gap: 8px;
    padding: 8px;
  }
  .seat-left, .seat-right { align-self: stretch; }
  .seat .bot-card { height: 100%; padding: 6px; gap: 4px; }
  .bot-id { flex-direction: column; gap: 4px; text-align: center; }
  .bot-avatar { width: 40px; height: 40px; flex-basis: 40px; }
  .bot-name { font-size: 0.7rem; }
  .bot-style { display: none; }
  .bot-hand .tile.mini { width: 10px; height: 16px; border-bottom-width: 2px; }
  .bot-status { text-align: center; font-size: 0.6rem; }

  .center { min-height: 180px; }
  .tile { width: 42px; height: 58px; }
  .tile.small { width: 24px; height: 34px; }
  .hand { gap: 3px; }
  .hand .tile.selected { transform: translateY(-8px); }
  .btn { padding: 12px 16px; }
}
