:root {
  color-scheme: light;
  font-family: system-ui, "PingFang TC", "Microsoft JhengHei", "Noto Sans CJK TC", sans-serif;
  color: #18342c;
  background: #e2efe7;
  --green: #087653;
  --muted: #526d61;
  --line: #e1eee7;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
h1, h2, p, ol, ul { margin: 0; }
button, input { font: inherit; }
button {
  border: 0; border-radius: 11px; padding: 0 16px; min-height: 43px;
  background: #086b4b; color: white; font-weight: 750; cursor: pointer;
}
button:disabled { opacity: .55; cursor: default; }
input {
  width: 100%; min-width: 0; border: 1px solid #ccdcd3; border-radius: 11px;
  padding: 9px 11px; background: #f6faf7; color: inherit; font-size: 16px;
}
:focus-visible { outline: 2px solid #10966c; outline-offset: 2px; }
.game {
  width: min(100%, 500px); margin: auto; min-height: 100dvh; padding: 12px;
  display: grid; gap: 10px; grid-template-rows: auto auto minmax(290px, 1fr) auto;
  background: linear-gradient(165deg, #d8f1e1, #f2f8f4 60%);
  box-shadow: 0 0 60px #25493812;
}
.masthead, .round-line { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.masthead { padding: 2px 3px; }
h1 { font-size: 21px; font-weight: 850; letter-spacing: .08em; }
#status {
  font-size: 12px; font-weight: 700; color: #6d5018; background: #fff4d7;
  border-radius: 20px; padding: 4px 8px;
}
#status[data-connected="true"] { color: #086044; background: #f2fff6; }
#status::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: currentColor; margin-right: 5px; vertical-align: 2px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 17px; box-shadow: 0 3px 12px #18462b0a; min-width: 0; }
.question { text-align: center; padding: 11px 15px 13px; }
#round { font-size: 15px; background: #e6f6ed; border-radius: 8px; padding: 4px 9px; }
#phase, #topic { color: var(--green); font-size: 13px; font-weight: 750; }
#clock { color: #b92538; font-weight: 850; line-height: 1.1; font-size: 35px; font-variant-numeric: tabular-nums; }
progress { display: block; appearance: none; border: 0; width: 100%; overflow: hidden; background: #e6f1ea; border-radius: 10px; }
progress::-webkit-progress-bar { background: #e6f1ea; border-radius: 10px; }
progress::-webkit-progress-value { background: #3bad76; border-radius: 10px; }
progress::-moz-progress-bar { background: #3bad76; border-radius: 10px; }
#timer { height: 6px; margin: 8px 0 12px; }
#category { font-size: clamp(22px, 7vw, 31px); line-height: 1.2; }
#hints { margin: 7px 0 9px; color: var(--green); font-weight: 700; font-size: 13px; overflow-wrap: anywhere; }
#letters { display: flex; justify-content: center; gap: 7px; min-height: 39px; }
.letter {
  display: grid; place-items: center; width: 42px; min-height: 39px;
  border-radius: 9px; border: 1px dashed #91bca6; background: #f3faf5;
  color: #426957; font-size: 20px; font-weight: 850;
}
.letter.shown { color: #075a3e; background: #d8f7e5; border-style: solid; }
#reveal { color: #086044; font-size: 13px; font-weight: 750; margin-top: 6px; overflow-wrap: anywhere; }
.boards { display: grid; grid-template-columns: minmax(0, 62fr) minmax(0, 38fr); gap: 8px; min-height: 0; }
.board { overflow: hidden; display: flex; flex-direction: column; }
.board h2, .chat h2, .previous h2 { font-size: 15px; font-weight: 850; }
.board h2 { padding: 10px 9px 8px; }
.board-scroll, #leaderboard { flex: 1; min-height: 0; overflow: auto; }
table { border-collapse: collapse; table-layout: fixed; width: 100%; text-align: left; font-size: 12px; }
th { font-size: 11px; color: var(--muted); background: #eff7f2; position: sticky; top: 0; z-index: 1; padding: 6px 2px; white-space: nowrap; }
th:first-child { width: 26%; padding-left: 7px; }
th:nth-child(2) { width: 23%; }
th:nth-child(3) { width: 21%; }
th:last-child { width: 30%; padding-right: 6px; }
td { border-bottom: 1px solid #edf4ef; padding: 7px 2px; overflow-wrap: anywhere; }
td:first-child { padding-left: 7px; }
td:last-child { padding-right: 6px; }
.rank { color: #5d4c34; font-size: 10px; }
.word { font-weight: 800; }
.count { color: #086044; background: #dff3e8; border-radius: 4px; padding: 0 2px; font-size: 9px; margin-left: 2px; }
.score { color: #086044; white-space: nowrap; font-weight: 750; font-variant-numeric: tabular-nums; }
.score progress { height: 4px; margin-top: 3px; }
.mine { background: #e0f7e9; }
.new-row { animation: enter .35s ease-out; }
@keyframes enter { from { opacity: .25; transform: translateY(6px); } }
.empty { color: var(--muted); font-size: 12px; padding: 8px 9px; }
.side { display: grid; grid-template-rows: minmax(0, 1fr) auto; gap: 8px; min-width: 0; min-height: 0; }
#leaderboard { list-style: none; padding: 0 7px; }
#leaderboard:empty { flex: 0; }
#leaderboard li {
  display: grid; grid-template-columns: 19px minmax(0, 1fr) auto; align-items: center;
  gap: 3px; min-height: 31px; padding: 3px 0; border-bottom: 1px solid #edf4ef; font-size: 11px;
}
.place { display: grid; place-items: center; border-radius: 6px; height: 19px; background: #eef5f0; font-weight: 800; }
.place-1 { background: #ffe199; color: #613d08; }
.place-2 { background: #dce5ee; color: #31485f; }
.place-3 { background: #f6d4bb; color: #673818; }
.nickname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.previous { padding: 8px 9px; }
.previous span { color: var(--green); }
.previous p { font-size: 11px; color: var(--muted); margin-top: 4px; overflow-wrap: anywhere; }
.chat { padding: 9px 10px 10px; }
#messages { list-style: none; padding: 3px 0; margin: 4px 0 6px; height: 92px; overflow: auto; }
#messages li { padding: 2px 0; font-size: 12px; overflow-wrap: anywhere; }
#messages .system { color: var(--green); font-weight: 700; }
#guess { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; }
dialog { width: min(calc(100% - 36px), 345px); padding: 21px; border: 1px solid var(--line); border-radius: 17px; color: inherit; }
dialog::backdrop { background: #153d34a0; }
#join { display: grid; gap: 12px; }
#join label { display: grid; gap: 5px; font-size: 14px; }
#join-error { color: #a22436; font-size: 13px; }
#toast {
  position: fixed; z-index: 4; bottom: 76px; left: 50%; transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 28px); border-radius: 12px; padding: 9px 15px;
  color: white; background: #17382f; text-align: center; font-size: 14px;
}
.celebration { position: fixed; inset: 0; z-index: 3; display: grid; place-items: center; background: #0c302478; overflow: hidden; pointer-events: none; }
#confetti { position: absolute; inset: 0; }
.celebration-copy {
  display: grid; gap: 7px; text-align: center; border: 2px solid #fff2ad;
  background: #075b43; color: #fff; border-radius: 22px; padding: 18px 22px;
  max-width: calc(100% - 34px); overflow-wrap: anywhere;
  box-shadow: 0 0 42px #ffe49492; animation: pop .55s both ease-out;
}
.celebration-copy strong { font-size: clamp(26px, 7vw, 47px); }
.celebration-copy span { color: #ffeb9b; font-size: 24px; font-weight: 800; }
@keyframes pop { from { opacity: 0; transform: scale(.58); } 70% { transform: scale(1.08); } }
.piece { position: absolute; top: -20px; width: 8px; height: 14px; background: var(--color); animation: fall var(--duration) var(--delay) linear both; }
@keyframes fall { to { transform: translate(var(--drift), calc(100dvh + 40px)) rotate(650deg); } }
@media (min-height: 720px) {
  .game { height: 100dvh; min-height: min-content; }
}
@media (max-width: 350px) {
  .game { padding: 7px; }
  .boards { gap: 5px; }
}
@media (prefers-reduced-motion: reduce) {
  .piece { display: none; }
  .new-row, .celebration-copy { animation: none; }
}
