:root {
  --ink: #33405a; --muted: #6d7c93; --line: #cfe6ee; --panel: rgba(255, 255, 255, .9);
  --accent: #ff7f96; --seat0: #ff8fa3; --seat1: #3fbfb8; --move: #ffa800; --place: #2fd08a;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; color: var(--ink); overflow: hidden;
  font: 16px/1.5 "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(255, 255, 255, .75), transparent 60%),
    linear-gradient(#c9f3f6, #8fdbe8 45%, #58b4d6);
}
#app { position: fixed; inset: 0; }
#stage { position: absolute; inset: 0; touch-action: none; }
#stage canvas { display: block; }

input, select, button { font: inherit; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--ink); }
button { cursor: pointer; box-shadow: 0 2px 0 rgba(51, 64, 90, .12); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
[hidden] { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.row label { width: 4em; color: var(--muted); }
.row input { flex: 1; min-width: 0; }
#joinCode { flex: 0 0 5.5em; text-transform: uppercase; }

/* ---------------------------------------------------------------- top bar */
#topbar { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; pointer-events: none; }
#topbar h1 { margin: 0; font-size: 1.15rem; color: #fff; text-shadow: 0 2px 6px rgba(40, 90, 120, .5); }
#topbar .row { margin: 0; pointer-events: auto; }
#topbar button { padding: 4px 12px; font-size: .9rem; }

/* ------------------------------------------------------------------- game */
#game { position: absolute; inset: 0; pointer-events: none; display: flex; flex-direction: column; align-items: center; padding: 48px 8px max(10px, env(safe-area-inset-bottom)); }
#game > *, #dock > * { pointer-events: auto; }
#dock { margin-top: auto; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.hud { margin: 6px 0 0; padding: 4px 16px; border-radius: 999px; background: var(--panel); font-weight: 700; box-shadow: 0 2px 8px rgba(40, 90, 120, .2); }
.hud:empty, .watchers:empty, .toast:empty { display: none; }
.watchers { margin: 4px 0 0; color: #fff; font-size: .85rem; text-shadow: 0 1px 3px rgba(40, 90, 120, .6); }
.toast { margin: 6px 0 0; padding: 2px 12px; border-radius: 999px; background: rgba(51, 64, 90, .75); color: #fff; font-size: .9rem; max-width: 92vw; }

.hand { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 18px; background: var(--panel); border: 3px solid transparent; box-shadow: 0 2px 10px rgba(40, 90, 120, .2); max-width: 100%; }
.hand.seat0 { --seat: var(--seat0); } .hand.seat1 { --seat: var(--seat1); }
.hand.turn { border-color: var(--seat); }
.hand .who { display: flex; flex-direction: column; line-height: 1.25; padding-right: 4px; min-width: 4.5em; }
.hand .who b { color: var(--seat); filter: brightness(.8); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 8em; }
.hand .who small { color: var(--muted); white-space: nowrap; }
.hand .who .danger { color: #e2445c; font-weight: 700; }
.hand button.piece { position: relative; width: 58px; height: 58px; padding: 0; border-radius: 16px; border: 2px solid var(--line); background: #fff; }
.hand button.piece img { width: 100%; height: 100%; object-fit: contain; display: block; }
.hand button.piece .count { position: absolute; right: -4px; bottom: -4px; min-width: 20px; height: 20px; border-radius: 10px; background: var(--seat); color: #fff; font-size: .75rem; font-weight: 700; line-height: 20px; text-align: center; }
.hand button.piece.empty { opacity: .3; }
.hand button.piece.can { border-color: var(--place); box-shadow: 0 0 0 2px var(--place); }
.hand button.piece.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent); transform: translateY(-4px); }
#handTop button.piece { width: 40px; height: 40px; border-radius: 12px; }

.info { display: flex; gap: 10px; align-items: center; width: min(560px, 100%); padding: 8px 14px; border-radius: 18px; background: var(--panel); box-shadow: 0 2px 10px rgba(40, 90, 120, .25); }
.info img { width: 72px; height: 72px; object-fit: contain; flex: none; }
.info h3 { margin: 0; font-size: 1.05rem; }
.info h3 small { font-weight: 400; color: var(--muted); margin-left: 6px; }
.info p { margin: 2px 0 0; font-size: .92rem; }
.info .tip { color: var(--muted); }
.info .state { font-weight: 700; }
.info .state.ok { color: #1f9a6b; } .info .state.no { color: #d9485f; } .info .state.look { color: #5b6fc7; }

/* ---------------------------------------------------------- speech bubbles */
.talks { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.talk { position: absolute; left: 0; top: 0; max-width: 13em; padding: 5px 12px; border-radius: 16px; background: #fff; border: 2px solid var(--seat0); font-size: .88rem; line-height: 1.35; box-shadow: 0 3px 10px rgba(40, 90, 120, .25); animation: pop .25s ease-out; transition: opacity .3s; white-space: normal; width: max-content; }
.talk.seat1 { border-color: var(--seat1); }
.talk::after { content: ""; position: absolute; left: 50%; bottom: -8px; width: 12px; height: 12px; margin-left: -6px; background: #fff; border: 2px solid; border-color: transparent var(--seat0) var(--seat0) transparent; transform: rotate(45deg); }
.talk.seat1::after { border-color: transparent var(--seat1) var(--seat1) transparent; }
.talk.leaving { opacity: 0; }
@keyframes pop { from { opacity: .2; translate: 0 10px; } to { opacity: 1; translate: 0 0; } }

/* ------------------------------------------------------------------ lobby */
.panel { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(480px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto; background: var(--panel); border-radius: 24px; padding: 18px 20px; box-shadow: 0 10px 40px rgba(40, 90, 120, .35); text-align: center; }
.panel .mascot { width: 120px; height: 120px; margin: -6px 0 -10px; animation: bob 3s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px); } }
.panel h2 { margin: 0; font-size: 1.6rem; }
.panel .lead { margin: 4px 0 10px; color: var(--muted); }
.panel .buttons { justify-content: center; }
.panel hr { border: 0; border-top: 1px dashed var(--line); margin: 12px 0; }
.status { color: var(--muted); margin: 8px 0 0; min-height: 1.5em; word-break: break-all; font-size: .9rem; }
.status .code { font-size: 1.5em; font-weight: 700; color: var(--ink); letter-spacing: .1em; }

dialog { border: 0; border-radius: 24px; padding: 18px 22px; width: min(560px, calc(100vw - 24px)); color: var(--ink); box-shadow: 0 10px 40px rgba(40, 90, 120, .4); }
dialog::backdrop { background: rgba(40, 90, 120, .45); }
dialog h2 { margin: 0 0 8px; }
dialog ol { padding-left: 1.3em; margin: 0 0 10px; }
dialog li { margin: 3px 0; }
.help-pieces { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 4px; }
.help-pieces li { display: flex; align-items: center; gap: 8px; font-size: .92rem; }
.help-pieces img { width: 44px; height: 44px; flex: none; }
dialog form { text-align: center; }

@media (max-width: 520px) {
  #topbar h1 { font-size: 1rem; }
  .hand { gap: 4px; padding: 5px 6px; }
  .hand button.piece { width: 50px; height: 50px; }
  #handTop button.piece { width: 34px; height: 34px; }
  .hand .who { min-width: 3.6em; font-size: .85rem; }
  .info img { width: 56px; height: 56px; }
}
