:root {
  --ink: #e8f4f6;
  --muted: #9bb8be;
  --gold: #e0b25a;
  --gold-deep: #b8862c;
  --sea-0: #041116;
  --sea-1: #0a2a33;
  --tile-w: 52px;
  --tile-h: 70px;
  --lift-x: 6px;
  --lift-y: 7px;
  --font: "Source Sans 3", "Segoe UI", sans-serif;
  --display: "Cormorant Garamond", Georgia, serif;
  --han: "Noto Sans SC", "Source Han Sans SC", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font);
  background: var(--sea-0);
}

button, input { font: inherit; }

.sea {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(97, 168, 186, 0.22), transparent 60%),
    radial-gradient(800px 400px at 80% 100%, rgba(32, 78, 98, 0.45), transparent 55%),
    linear-gradient(180deg, #062028 0%, #041116 55%, #031014 100%);
  pointer-events: none;
  z-index: 0;
}

.sea::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle at 20% 40%, rgba(255,255,255,.035) 0 1px, transparent 1.5px);
  background-size: 140px 90px;
  animation: drift 28s linear infinite;
  opacity: .7;
}

@keyframes drift {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(-70px, -40px, 0); }
}

/* ---------- Prompt UI (start) ---------- */

.prompt-ui {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(2, 10, 14, 0.55);
  backdrop-filter: blur(10px);
}

.prompt-card {
  width: min(440px, 100%);
  padding: 28px 28px 26px;
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(18, 48, 58, 0.96), rgba(8, 24, 30, 0.96));
  border: 1px solid rgba(224, 178, 90, 0.28);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  text-align: center;
}

.prompt-whale {
  width: 168px;
  height: 168px;
  margin: -8px auto 8px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 40% 35%, rgba(255,255,255,.16), transparent 45%),
    radial-gradient(circle at 50% 55%, #12343e, #07161b);
  border: 2px solid rgba(224, 178, 90, 0.45);
  display: grid;
  place-items: center;
  overflow: hidden;
  box-shadow: 0 0 0 8px rgba(224, 178, 90, 0.08);
}

.prompt-whale img {
  width: 150%;
  height: 150%;
  object-fit: cover;
  object-position: 50% 42%;
}

.prompt-kicker {
  margin: 0 0 4px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--gold);
}

.prompt-card h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 56px;
  line-height: 0.95;
  font-weight: 700;
}

.prompt-lead {
  margin: 10px 0 18px;
  color: var(--muted);
  line-height: 1.45;
  font-size: 15px;
}

.field {
  display: grid;
  gap: 6px;
  text-align: left;
  margin-bottom: 16px;
}

.field span, .layouts legend {
  font-size: 13px;
  color: var(--muted);
}

.field input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.28);
  color: var(--ink);
  outline: none;
}

.field input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(224, 178, 90, 0.18);
}

.layouts {
  border: 0;
  margin: 0 0 18px;
  padding: 0;
  display: grid;
  gap: 8px;
  text-align: left;
}

.layout-opt {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 9px 11px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.03);
  cursor: pointer;
}

.layout-opt:has(input:checked) {
  border-color: rgba(224, 178, 90, 0.55);
  background: rgba(224, 178, 90, 0.08);
}

.layout-opt input { accent-color: var(--gold); }

.layout-opt strong { display: block; font-size: 14px; }
.layout-opt em { font-style: normal; color: var(--muted); font-size: 12px; }

.btn {
  appearance: none;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.06);
  color: var(--ink);
  border-radius: 999px;
  padding: 9px 14px;
  cursor: pointer;
  transition: transform .12s ease, background .12s ease;
}

.btn:hover { background: rgba(255,255,255,.12); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: default; }

.btn.primary {
  width: 100%;
  padding: 12px 16px;
  border: 0;
  background: linear-gradient(180deg, #efc36d, #c8922e);
  color: #2a1a05;
  font-weight: 700;
}

.btn.ghost { background: transparent; }

/* ---------- HUD / table ---------- */

.hud {
  position: relative;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 16px 24px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-whale {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  object-position: 50% 40%;
  background: #102830;
  border: 1px solid rgba(224, 178, 90, 0.4);
}

.brand strong {
  display: block;
  font-family: var(--display);
  font-size: 22px;
  line-height: 1;
}

.brand span { color: var(--muted); font-size: 13px; }

.stats {
  display: flex;
  gap: 18px;
  margin: 0;
}

.stats div { min-width: 52px; }
.stats dt {
  margin: 0;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.stats dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 18px;
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.table {
  position: relative;
  z-index: 1;
  height: calc(100vh - 88px);
  padding: 4px 12px 16px;
}

.board-wrap {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.board {
  position: relative;
  transform-origin: center center;
}

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

.tile {
  position: absolute;
  width: var(--tile-w);
  height: var(--tile-h);
  border-radius: 7px;
  background:
    linear-gradient(165deg, #fffef8 0%, #f4ead3 70%, #e7d7b4 100%);
  color: #2b2116;
  box-shadow:
    inset 0 1px 0 #fff,
    2px 2px 0 #c9a56a,
    4px 5px 0 #7a5628,
    6px 8px 12px rgba(0,0,0,.35);
  user-select: none;
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease;
}

.tile .face {
  position: absolute;
  inset: 5px 5px 7px;
  border-radius: 4px;
  border: 1px solid rgba(140, 100, 40, 0.18);
  background: linear-gradient(180deg, #fffaf0, #f7edd8);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.tile.blocked { filter: saturate(.85) brightness(.92); }
.tile.free { cursor: pointer; }
.tile.free:hover { transform: translate(-1px, -2px); }

.tile.selected {
  transform: translate(-2px, -4px);
  box-shadow:
    inset 0 1px 0 #fff,
    0 0 0 2px #f0d27a,
    3px 3px 0 #c9a56a,
    5px 6px 0 #7a5628,
    0 0 18px rgba(224, 178, 90, .55);
}

.tile.hint {
  box-shadow:
    inset 0 1px 0 #fff,
    0 0 0 2px #6ad0c3,
    3px 3px 0 #c9a56a,
    5px 6px 0 #7a5628,
    0 0 16px rgba(90, 210, 190, .5);
}

.tile.removing {
  animation: pop .28s ease forwards;
  pointer-events: none;
}

@keyframes pop {
  to { transform: scale(.4) translateY(-12px); opacity: 0; }
}

.han {
  font-family: var(--han);
  font-weight: 700;
  line-height: 1;
}

.mark-lg { font-size: 28px; }
.mark-md { font-size: 22px; }
.suit {
  font-size: 11px;
  letter-spacing: .04em;
  color: #8a3a2a;
}

.pips {
  display: grid;
  width: 28px;
  height: 40px;
  place-items: center;
}
.pip {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff6b5b, #b51d18);
  box-shadow: 0 0 0 1px rgba(120, 20, 10, .25);
}
.pip.blue { background: radial-gradient(circle at 35% 30%, #6eb6ff, #1c5ea8); }
.pip.green { background: radial-gradient(circle at 35% 30%, #7ad08a, #1f7a38); }

.bamboos {
  display: flex;
  gap: 2px;
  align-items: flex-end;
  height: 38px;
}
.stick {
  width: 5px;
  border-radius: 3px;
  background: linear-gradient(90deg, #8fd98a, #2f8a3a 45%, #1f5d28);
  box-shadow: inset 1px 0 0 rgba(255,255,255,.35);
}

.dragon-red { color: #c41616; }
.dragon-green { color: #1b7a32; }
.dragon-white {
  width: 26px;
  height: 34px;
  border: 2px solid #2b4d88;
  border-radius: 3px;
  background: #fbf8ef;
}

.wind { color: #1d4f86; }
.flower { color: #b4236a; }
.season { color: #b86a12; }

.caption {
  position: absolute;
  bottom: 3px;
  right: 4px;
  font-size: 9px;
  opacity: .55;
  font-weight: 700;
}

/* ---------- chrome ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 30;
  margin: 0;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(8, 22, 28, 0.92);
  border: 1px solid rgba(224, 178, 90, 0.3);
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 10, 14, 0.62);
}

.modal[hidden], .toast[hidden], .prompt-ui[hidden] { display: none !important; }

.modal-card {
  width: min(440px, 100%);
  padding: 24px;
  border-radius: 22px;
  background: linear-gradient(180deg, #16343d, #0b1c22);
  border: 1px solid rgba(224, 178, 90, 0.28);
}

.modal-card h2 {
  margin: 0 0 12px;
  font-family: var(--display);
  font-size: 32px;
}

.modal-card ul {
  margin: 0 0 14px;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.5;
}

.keys { color: var(--muted); font-size: 14px; }
kbd {
  display: inline-block;
  padding: 0 6px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,.2);
  background: rgba(255,255,255,.06);
  font-size: 12px;
}

.end-card { text-align: center; }
.end-card img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 50%;
  background: #102830;
}
.end-actions { display: grid; gap: 8px; margin-top: 16px; }

@media (max-width: 820px) {
  :root { --tile-w: 42px; --tile-h: 56px; }
  .prompt-card h1 { font-size: 44px; }
  .hud { padding: 10px 12px 6px; }
  .stats { gap: 10px; }
  .table { height: calc(100vh - 140px); }
}

@media (max-width: 560px) {
  .actions { width: 100%; }
  .actions .btn { flex: 1; padding: 8px 8px; font-size: 13px; }
}
