:root {
  --bg: #f4f1ea;
  --ink: #2f3338;
  --sub: #7a766c;
  --line: #d9d4c8;
  --acc: #d42940;
  --ok: #4f9a3a;
  --dot: 'DotGothic16', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: system-ui, -apple-system, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  /* No double-tap zoom (iOS zooms in when a picker cell is tapped twice). */
  touch-action: manipulation;
}
button, canvas, .chips, .hist { touch-action: manipulation; -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; }
#app { max-width: 440px; margin: 0 auto; padding: 0 12px calc(16px + env(safe-area-inset-bottom)); }

.top { display: flex; align-items: baseline; gap: 10px; padding: 10px 2px 8px; }
.top h1 { font-family: var(--dot); font-size: 22px; margin: 0; letter-spacing: .04em; }
.top .no { font-family: var(--dot); color: var(--sub); font-size: 14px; }
.top .left { margin-left: auto; font-size: 13px; color: var(--sub); }
.top .left b { font-family: var(--dot); font-size: 18px; color: var(--ink); }
/* Language switch: a globe and the short name, with the real <select> laid invisibly over them. */
.lang { position: relative; flex: none; align-self: center; display: inline-flex; align-items: center; gap: 3px; padding: 3px 7px; border: 1px solid var(--line); border-radius: 999px; font-size: 11px; color: var(--sub); line-height: 1; }
.lang svg { width: 13px; height: 13px; }
.lang select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; font-size: 16px; cursor: pointer; }

/* Korean and Chinese: the system's own fonts (DotGothic16 has no hangul, and draws the hanzi it has in Japanese forms). */
:lang(ko) { --cjk: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', sans-serif; }
:lang(zh-Hans) { --cjk: system-ui, -apple-system, 'PingFang SC', 'Noto Sans SC', 'Microsoft YaHei', sans-serif; --dot: var(--cjk); }
:lang(zh-Hant) { --cjk: system-ui, -apple-system, 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', sans-serif; --dot: var(--cjk); }
:lang(ko) body, :lang(zh-Hans) body, :lang(zh-Hant) body { font-family: var(--cjk); }
:lang(zh-Hans) .top h1, :lang(zh-Hant) .top h1 { font-family: 'DotGothic16', system-ui, sans-serif; }

.main { --bw: min(100%, 300px); }
.board { position: relative; width: var(--bw); margin: 0 auto; border: 3px solid var(--ink); background: var(--ink); }
.board canvas { display: block; width: 100%; aspect-ratio: 1; image-rendering: pixelated; }

.chips { display: grid; grid-template-columns: repeat(12, 1fr); gap: 3px; width: var(--bw); margin: 6px auto 0; }
.chip { aspect-ratio: 2 / 1; background: var(--c); border-radius: 2px; position: relative; opacity: .55; }
.chip { cursor: pointer; }
.chip.s1 { opacity: 1; outline: 2px solid var(--ink); outline-offset: 1px; }
.chip.on { opacity: 1; box-shadow: 0 0 0 3px #fff, 0 0 0 5px #14171a; z-index: 1; }
.chip.s-1 { opacity: .18; }
.chip.s-1::after { content: ''; position: absolute; inset: 45% -10%; background: var(--ink); transform: rotate(-45deg); }

.hist { list-style: none; padding: 0; margin: 6px auto 0; display: grid; grid-template-columns: repeat(var(--n, 7), 1fr); gap: 4px; width: min(100%, 320px); }
.hist li { height: 40px; border: 2px solid var(--line); border-radius: 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #fffdf8; }
.hist li.empty { background: transparent; border-style: dashed; }
.hist li.hit { border-color: var(--ok); background: #eaf5e3; }
.hist li[data-g] { cursor: pointer; }
.hist li.on { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink); background: #ffe6a6; }
.he { display: flex; } .he img { width: 20px; height: 20px; }
.hn { font-size: 10px; color: var(--sub); font-family: var(--dot); }

.play { margin-top: 10px; }
.pick-head { display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 12px; background: #fffdf8; border: 2px solid var(--line); border-radius: 10px; }
.pv-name { flex: 1; min-width: 0; font-size: 14px; display: flex; align-items: center; gap: 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.pv-e { display: flex; flex: none; } .pv-e img { width: 26px; height: 26px; }
.pv-was { flex: none; font-size: 11px; color: var(--sub); border: 1px solid var(--line); border-radius: 999px; padding: 1px 7px; }
.pv-ph { color: var(--sub); font-size: 12px; white-space: normal; line-height: 1.35; }
.go { flex: none; border: 0; border-radius: 8px; background: var(--acc); color: #fff; font-weight: 700; padding: 10px 18px; font-size: 15px; cursor: pointer; }
.go.off { background: var(--line); color: #fff; cursor: default; }

.q { width: 100%; margin-top: 6px; padding: 8px 12px; font-size: 16px; border: 2px solid var(--line); border-radius: 10px; background: #fffdf8; color: var(--ink); }
.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 2px; margin-top: 6px; height: 264px; overflow-y: auto; background: #fffdf8; border: 2px solid var(--line); border-radius: 10px; padding: 4px; overscroll-behavior: contain; }
.pk { height: 44px; border: 0; background: none; border-radius: 8px; cursor: pointer; padding: 0; display: flex; align-items: center; justify-content: center; }
.pk img { width: 30px; height: 30px; pointer-events: none; -webkit-user-drag: none; }
.pk.sel { background: #ffe6a6; box-shadow: inset 0 0 0 2px var(--ink); }
.pk.used { opacity: .2; cursor: default; }
.pk-none { grid-column: 1 / -1; text-align: center; color: var(--sub); font-size: 13px; }

.result { margin-top: 14px; text-align: center; }
.res-head { font-family: var(--dot); font-size: 24px; margin: 0; }
.answer { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 6px 0 10px; }
.ans-e { display: flex; } .ans-e img { width: 48px; height: 48px; }
.ans-n { font-size: 15px; }
.dist { width: min(100%, 320px); margin: 0 auto 12px; text-align: left; }
.dist-h { font-size: 12px; color: var(--sub); margin: 0 0 4px; text-align: center; }
.bar { display: grid; grid-template-columns: 16px 1fr 40px; gap: 6px; align-items: center; font-family: var(--dot); font-size: 13px; margin: 2px 0; }
.bar i { display: block; height: 14px; background: var(--line); border-radius: 2px; }
.bar.me i { background: var(--ok); }
.bar b { font-weight: 400; color: var(--sub); }
.btns { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-width: 220px; padding: 12px 18px; border-radius: 999px; border: 2px solid var(--ink); background: #fffdf8; font-size: 15px; font-weight: 700; text-decoration: none; color: var(--ink); cursor: pointer; }
.btn.x { background: #000; color: #fff; border-color: #000; }
.btn.x svg { width: 18px; height: 18px; }
.next { font-size: 12px; color: var(--sub); margin: 10px 0 0; }

.foot { margin-top: 18px; text-align: center; }
.credit { font-size: 11px; color: var(--sub); margin: 8px 0 0; }
.credit a { color: inherit; }

/* While playing, the board, the history and the picker share one screen: the picker takes what is
   left, so a picked emoji is always seen laid over the board. Small phones shrink the board. */
body.playing .main { height: calc(100vh - 46px); height: calc(100dvh - 46px); display: flex; flex-direction: column; padding-bottom: 8px; }
body.playing .main { --bw: max(180px, min(100%, 300px, calc(100vh - 470px))); --bw: max(180px, min(100%, 300px, calc(100dvh - 470px))); }
body.playing .play { flex: 1; min-height: 0; display: flex; flex-direction: column; margin-top: 8px; }
body.playing .picker { flex: 1; height: auto; min-height: 132px; }

/* What a tapped cell or colour is: a dark label over the bottom of the board. */
.info { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); max-width: calc(100% - 16px); white-space: nowrap; display: flex; flex-wrap: nowrap; align-items: center; justify-content: center; gap: 2px 6px;
  padding: 6px 12px; border-radius: 10px; background: rgba(20, 23, 26, .9); color: #fff; font-size: 13px; line-height: 1.3; pointer-events: none; text-align: center; }
.info.up { bottom: auto; top: 8px; }
.info[hidden] { display: none; }
.info b { font-weight: 700; color: #9be08a; }
.info b.no { color: #ff9a9a; }
.info small { font-size: 11px; color: #d6dbe0; display: inline-flex; flex-wrap: wrap; align-items: center; gap: 2px 4px; }
.info .sw { display: inline-block; width: 12px; height: 12px; border-radius: 2px; background: var(--c); box-shadow: 0 0 0 1px rgba(255,255,255,.7); vertical-align: -1px; margin-right: 2px; }
.info .sw.empty { background: repeating-linear-gradient(45deg, #ebe7de 0 3px, #cfc8b9 3px 5px); }
