:root {
  --sky: #2fa7f0;
  --sea: #07357f;
  --yellow: #ffe600;
  --red: #e5261f;
  --green: #39d353;
  --wood: #b5702c;
  --wood-dark: #5b3210;
  --plank: #f3d9a4;
  --ink: #2b1605;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--sea);
  font-family: 'Mali', 'Sarabun', system-ui, sans-serif;
  font-weight: 500;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

[hidden] { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
  overflow-y: auto;
}

/* A plank sign bobbing in the scene, not a card: thick edge, hard shadow, nailed corners. */
.sign {
  position: relative;
  width: min(560px, 100%);
  margin: auto;
  padding: 18px 20px 20px;
  text-align: center;
  background: repeating-linear-gradient(0deg, var(--plank) 0 46px, #e6c98e 46px 48px);
  border: 6px solid var(--wood-dark);
  border-radius: 6px 14px 8px 12px;
  box-shadow: 8px 8px 0 rgba(0, 20, 60, .55);
}
.sign::before, .sign::after {
  content: '';
  position: absolute;
  top: 8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--wood-dark);
}
.sign::before { left: 8px; }
.sign::after { right: 8px; }
.sign.small { width: min(320px, 100%); }
.sign.wide { width: min(620px, 100%); }

h2 {
  margin: 6px 0 8px;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.25;
}

.logo { margin: -6px 0 0; line-height: 0; }
.logo svg { width: min(420px, 100%); height: auto; overflow: visible; }
.logo text {
  font: 700 118px 'Mali', sans-serif;
  fill: url(#wordart);
  stroke: #fff;
  stroke-width: 12px;
  paint-order: stroke;
  stroke-linejoin: round;
  filter: drop-shadow(5px 6px 0 var(--sea));
}

.intro { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 6px; }
.how { margin: 0; line-height: 1.5; text-align: left; }
.art { display: block; width: 96px; height: 96px; margin: 0 auto; flex: none; }
.corner-art { position: absolute; top: 4px; left: 18px; width: 64px; height: 64px; }

.credit { margin: 10px 0 0; font-size: .8rem; }
.credit a { color: inherit; }

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.btn {
  min-height: 46px;
  padding: 6px 18px;
  border: 4px solid var(--wood-dark);
  border-radius: 8px;
  background: #fff6e0;
  box-shadow: 3px 3px 0 var(--wood-dark);
  font: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
  cursor: pointer;
}
.btn:active { transform: translate(3px, 3px); box-shadow: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--yellow); font-size: 1.3rem; padding-inline: 26px; }

:focus-visible { outline: 4px solid var(--red); outline-offset: 2px; }

.final {
  margin: 0;
  font-size: clamp(2.6rem, 11vw, 3.8rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: .03em;
  color: var(--yellow);
  -webkit-text-stroke: 2px var(--wood-dark);
  paint-order: stroke fill;
  text-shadow: 3px 3px 0 var(--wood-dark);
}

.facts {
  list-style: none;
  margin: 6px 0 12px;
  padding: 0;
  line-height: 1.5;
}

.nick { margin-bottom: 12px; }
.nick label { display: block; font-weight: 700; margin-bottom: 4px; }
.nick input {
  flex: 1 1 150px;
  min-width: 0;
  min-height: 46px;
  padding: 6px 10px;
  border: 4px solid var(--wood-dark);
  border-radius: 8px;
  background: #fff;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
}
.note { min-height: 1.3em; margin: 6px 0 0; font-size: .9rem; }

.corner {
  position: fixed;
  right: max(8px, env(safe-area-inset-right));
  bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 5;
  width: 44px;
  height: 44px;
  border: 3px solid var(--wood-dark);
  border-radius: 8px;
  background: var(--plank);
  font-size: 1.2rem;
  cursor: pointer;
}

/* Empty unless Cloudflare needs the player to confirm something, once a game has ended. */
.turnstile { display: flex; justify-content: center; }
.turnstile:not(:empty) { margin-bottom: 10px; }

.menu-btn {
  bottom: calc(max(8px, env(safe-area-inset-bottom)) + 52px);
  width: auto;
  min-width: 44px;
  padding: 0 8px;
  font: inherit;
  font-weight: 700;
  font-size: .95rem;
  color: var(--ink);
}

.wide-btn { display: block; width: 100%; }
.menu-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }

.rules { max-height: min(66vh, 480px); overflow-y: auto; padding: 8px 10px; text-align: left; background: #fff6e0; border: 3px solid var(--wood-dark); border-radius: 6px; line-height: 1.5; }
.rules h3 { margin: 10px 0 2px; font-size: 1.05rem; font-weight: 700; color: var(--red); }
.rules h3:first-child { margin-top: 0; }
.rules p { margin: 0 0 6px; }
.rules table { width: 100%; border-collapse: collapse; margin-bottom: 6px; }
.rules th { padding: 3px 8px 3px 0; font-weight: 500; text-align: left; }
.rules td { padding: 3px 0; font-weight: 700; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.rules tr + tr > * { border-top: 2px dotted rgba(91, 50, 16, .35); }

.close {
  position: absolute;
  top: 8px;
  right: 22px;
  width: 44px;
  height: 44px;
  border: 0;
  background: none;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}

.tabs { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; }
.tab, .chip {
  min-height: 40px;
  padding: 4px 12px;
  border: 3px solid var(--wood-dark);
  border-radius: 8px;
  background: #fff6e0;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.tab[aria-selected='true'], .chip[aria-pressed='true'] { background: var(--yellow); font-weight: 700; }
.period { display: flex; gap: 4px; justify-content: center; margin: 6px 0; }
.chip { min-height: 34px; padding: 2px 10px; font-size: .9rem; }

.board-body {
  height: min(46vh, 340px);
  overflow-y: auto;
  padding: 6px;
  margin-top: 6px;
  background: #fff6e0;
  border: 3px solid var(--wood-dark);
  border-radius: 6px;
  text-align: left;
}
.board-body .empty { margin: 0; padding: 26px 8px; text-align: center; line-height: 1.5; }

.lb { list-style: none; margin: 0; padding: 0; }
.lb li {
  display: grid;
  grid-template-columns: 2em 34px minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  padding: 3px 2px;
}
.lb li + li { border-top: 2px dotted rgba(91, 50, 16, .35); }
.lb.players li { grid-template-columns: 2em minmax(0, 1fr) auto; }
.lb .pos { font-weight: 700; text-align: right; }
.lb img { width: 34px; height: 34px; }
/* overflow clips Thai marks above the line, so the box needs room for them. */
.lb .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.8; }
.lb .num { font-weight: 700; font-variant-numeric: tabular-nums; }

.vs { display: flex; align-items: center; justify-content: center; gap: 14px; text-align: center; line-height: 1.2; }
.vs-side b { display: block; font-size: 1.6rem; color: var(--red); font-variant-numeric: tabular-nums; }
.vs-mid { font-weight: 700; }
.vs-trio { margin: 4px 0 8px; padding-bottom: 6px; text-align: center; font-weight: 700; border-bottom: 3px solid var(--wood-dark); }

.bar { height: 10px; margin-top: 2px; background: var(--red); border-radius: 0 5px 5px 0; min-width: 3px; }

.book {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
  text-align: center;
  font-size: .85rem;
  line-height: 1.25;
}
.book img { display: block; width: 64px; height: 64px; margin: 0 auto 2px; }
.book .locked img { filter: brightness(.1) contrast(.6); opacity: .5; }
.book b { display: block; }
.mine-best { margin: 0 0 8px; text-align: center; font-weight: 700; }

@media (max-height: 560px) and (orientation: landscape) {
  .how, .sign > .art:not(.corner-art) { display: none; }
  .intro .art { width: 64px; height: 64px; }
  .logo svg { width: 220px; }
  .board-body { height: 38vh; }
}

@media (prefers-reduced-motion: reduce) {
  .btn:active { transform: none; }
}
