@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@400;500;600;700&family=Noto+Sans+JP:wght@400;500;700&display=swap');

/* Tokens shared with Goi-Match (docs/goimatch_ui_design_rules.html) — same series, same cabinet. */
:root {
  --page-bg:  #100805;
  --bg:       #2a1810;
  --board:    #5c3220;
  --bdark:    #3d2015;
  --shadow:   #1a0a04;
  --pin:      #d4a843;
  --yellow:   #f5c842;
  --green:    #4caf6a;
  --red:      #e05050;
  --paper:    #f7efe0;
  --ink:      #2a1810;
  --ui-sz-label: 11px; --ui-sz-ctrl: 13px; --ui-sz-title: 22px;
  --sp-xs: 4px; --sp-sm: 8px; --sp-md: 12px; --sp-lg: 16px; --sp-xl: 20px;
  --ctrl-radius: 7px; --ctrl-border: 2px;
  --fu: 'Noto Sans Thai', 'Noto Sans JP', sans-serif;
  --fj: 'Noto Sans JP', 'Yu Gothic', 'Hiragino Sans', 'Meiryo', sans-serif;
  --grid-n: 10;
  --cell: min(56px, calc((100vw - 32px) / var(--grid-n)), calc((100vh - 110px) / var(--grid-n)));
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  background: var(--bg);
  color: #f5ead8;
  font-family: var(--fu);
  display: flex; flex-direction: column;
  background-image:
    repeating-linear-gradient(0deg, transparent, transparent 31px, rgba(0,0,0,.12) 31px, rgba(0,0,0,.12) 32px),
    repeating-linear-gradient(90deg, transparent, transparent 31px, rgba(0,0,0,.12) 31px, rgba(0,0,0,.12) 32px);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── Header ── */
header {
  background: var(--bdark); border-bottom: 3px solid var(--shadow);
  padding: 4px 12px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  box-shadow: 0 3px 0 rgba(0,0,0,.4);
}
.logo-img { height: 40px; }
.logo { font-size: 16px; color: var(--yellow); text-shadow: 2px 2px 0 #8b5e00; letter-spacing: 1px; white-space: nowrap; }
.logo span { color: #f5ead8; font-family: var(--fj); }
.hdr-ctrl { margin-left: auto; display: flex; gap: var(--sp-md); align-items: center; flex-wrap: wrap; }
select { font: inherit; font-size: var(--ui-sz-ctrl); background: var(--board); color: #f5ead8; border: var(--ctrl-border) solid var(--shadow); border-radius: var(--ctrl-radius); padding: 3px 6px; }
.tg { display: flex; border: var(--ctrl-border) solid var(--shadow); border-radius: var(--ctrl-radius); overflow: hidden; }
.tb { font: inherit; font-size: var(--ui-sz-ctrl); font-weight: 600; background: var(--board); color: #f5ead8; border: 0; padding: 4px 10px; cursor: pointer; }
.tb.on { background: var(--yellow); color: var(--ink); }
.btn { font: inherit; font-size: var(--ui-sz-ctrl); font-weight: 600; background: var(--yellow); color: var(--ink); border: var(--ctrl-border) solid var(--shadow); border-radius: var(--ctrl-radius); padding: 5px 12px; cursor: pointer; box-shadow: 1px 1px 0 var(--shadow); }
.btn:hover { transform: translate(-1px,-1px); box-shadow: 3px 3px 0 var(--shadow); }
.btn.sm { font-size: var(--ui-sz-label); padding: 2px 8px; background: var(--board); color: #f5ead8; }
.btn.sec { background: var(--board); color: #f5ead8; }

/* ── Settings dropdown (Goi-Match #settingsPanel look) ── */
#settingsPanel { display: none; position: fixed; z-index: 500; background: var(--board); border: 3px solid var(--shadow); border-radius: 10px; padding: var(--sp-md) var(--sp-lg); box-shadow: 4px 4px 0 var(--shadow); gap: var(--sp-sm) var(--sp-lg); align-items: center; }
#settingsPanel.open { display: grid; grid-template-columns: max-content max-content; }
.sblb { font-size: var(--ui-sz-ctrl); font-weight: 600; color: rgba(245,234,216,.85); white-space: nowrap; }
.sblb.sec-head { color: var(--pin); font-size: 10px; letter-spacing: 1px; text-transform: uppercase; margin-top: var(--sp-xs); }
#settingsPanel .tg, #settingsPanel select { width: 180px; }
#settingsPanel .tb { flex: 1; font-size: var(--ui-sz-ctrl); padding: 5px 0; }

/* ── Board ── */
#game { flex: 1; display: flex; gap: var(--sp-xl); padding: var(--sp-lg); justify-content: center; align-items: flex-start; flex-wrap: wrap; }
#boardWrap { position: relative; box-sizing: content-box; width: calc(var(--cell) * var(--grid-n)); height: calc(var(--cell) * var(--grid-n)); background: var(--paper); border: 4px solid var(--shadow); border-radius: 8px; box-shadow: 0 6px 0 var(--shadow); touch-action: none; user-select: none; -webkit-user-select: none; }
#grid { display: grid; grid-template-columns: repeat(var(--grid-n), var(--cell)); grid-auto-rows: var(--cell); }
.cell { display: flex; align-items: center; justify-content: center; box-shadow: inset 0 0 0 0.5px rgba(42,24,16,.10); font-family: var(--fj); font-size: calc(var(--cell) * 0.55); font-weight: 500; color: var(--ink); line-height: 1; }
#pills { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#pills line { stroke-width: 0.78; stroke-linecap: round; opacity: .45; }
#pills line.drag { stroke: var(--yellow); opacity: .6; }
#pills line.miss { stroke: var(--red); opacity: .5; }
/* All-found badge: a small box over the board, the found words stay readable behind it. */
#banner { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; pointer-events: none; }
#banner.show { display: flex; }
.banner-box { background: var(--bdark); color: var(--yellow); border: 3px solid var(--shadow); border-radius: 12px; padding: var(--sp-md) var(--sp-xl); box-shadow: 4px 4px 0 var(--shadow); text-align: center; }
#bannerTitle { font-size: var(--ui-sz-title); font-weight: 700; }
#bannerStats { font-size: var(--ui-sz-ctrl); color: #f5ead8; margin-top: var(--sp-xs); }

/* ── Checklist ── */
#side { width: min(360px, 100%); }
.side-head { font-size: var(--ui-sz-label); font-weight: 600; color: var(--pin); margin-bottom: var(--sp-sm); }
#list { list-style: none; display: flex; flex-direction: column; gap: var(--sp-xs); }
#list li { display: grid; grid-template-columns: 22px 1fr auto; grid-template-rows: auto auto; column-gap: var(--sp-sm); align-items: center; background: var(--board); border: var(--ctrl-border) solid var(--shadow); border-radius: var(--ctrl-radius); padding: 5px 8px; }
#list li .box { width: 16px; height: 16px; border: 2px solid var(--pin); border-radius: 4px; grid-row: span 2; }
#list li.done .box { background: var(--green); border-color: var(--green); }
#list li.done .box::after { content: '✓'; color: #fff; font-size: 12px; font-weight: 700; display: block; text-align: center; line-height: 12px; }
#list li .clue { font-size: 14px; font-weight: 500; }
#list li .ans { grid-column: 2; font-family: var(--fj); font-size: 15px; letter-spacing: 2px; color: var(--yellow); min-height: 1.2em; }
#list li .ans small { font-size: 11px; color: rgba(245,234,216,.6); margin-left: 6px; letter-spacing: 0; }
#list li.revealed .ans { color: rgba(245,234,216,.6); }
#list li .btn { grid-column: 3; grid-row: span 2; }

@media (max-width: 767px) { #game { padding: var(--sp-sm); gap: var(--sp-md); } .logo { font-size: 13px; } }

#splash { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; font-size: 16px; color: var(--pin); z-index: 100; }
#splash.hide { display: none; }

/* ── Debug autoplay panel (?debug only) ── */
#debugPanel { position: fixed; right: 12px; bottom: 12px; z-index: 9999; width: 280px; background: rgba(18,13,28,.96); color: #f5ead8; border: 1px solid #6b5a90; border-radius: 8px; box-shadow: 0 6px 22px rgba(0,0,0,.5); font: 12px/1.4 system-ui, sans-serif; padding: 8px 10px; user-select: none; }
#debugPanel h4 { margin: 0 0 6px; font-size: 11px; letter-spacing: 1px; color: #d4b46a; text-transform: uppercase; }
#debugPanel h4 span { float: right; color: rgba(245,234,216,.5); text-transform: none; letter-spacing: 0; }
#debugPanel div { margin: 3px 0; }
#debugPanel button { font: inherit; margin: 2px 3px 2px 0; padding: 3px 9px; background: #2d2548; color: #f5ead8; border: 1px solid #5a4a82; border-radius: 4px; cursor: pointer; }
#debugPanel button.on { background: #5a4a82; }
