* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; height: 100dvh; overscroll-behavior: none; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #eafaf8;
  background: radial-gradient(circle at 50% 0%, #135a63 0%, #0b2e3a 55%, #061722 100%) fixed;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
}
:lang(zh-Hant) body, :lang(zh-Hant) button { font-family: system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

#app { height: 100%; display: flex; justify-content: center; }
.screen { width: 100%; max-width: 720px; height: 100%; display: flex; flex-direction: column; align-items: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }

/* Menu */
#menu { position: relative; overflow-y: auto; justify-content: safe center; gap: 14px; }
.logo { font-size: clamp(48px, 13vw, 80px); margin: 0; letter-spacing: -1px; font-weight: 800;
  background: linear-gradient(90deg, #ff5d73, #ffa53a, #ffe14d, #3ddc84, #3fa7ff, #c06bff);
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.tag { margin: -8px 0 18px; opacity: .7; letter-spacing: 3px; text-transform: uppercase; font-size: 13px; }
.big { width: min(360px, 90%); padding: 16px 20px; border-radius: 16px; border: 1px solid rgba(255,255,255,.18);
  background: linear-gradient(180deg, rgba(255,255,255,.14), rgba(255,255,255,.05)); font-size: 22px; font-weight: 700;
  text-align: left; transition: transform .1s, background .2s; }
.big:hover { background: linear-gradient(180deg, rgba(255,255,255,.22), rgba(255,255,255,.08)); }
.big:active { transform: scale(.98); }
.big small { display: block; font-size: 13px; font-weight: 400; opacity: .75; margin-top: 4px; }
.big small b { font-weight: 700; color: #ffe14d; }
.link { background: none; border: none; opacity: .75; text-decoration: underline; text-underline-offset: 3px; font-size: 15px; padding: 8px; }
.lang { position: absolute; top: 12px; right: 12px; padding: 6px 12px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.08); font-size: 14px; }

/* Top bar */
.topbar { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.topbar h2 { margin: 0; font-size: 18px; text-align: center; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { width: 40px; height: 40px; border-radius: 12px; border: 1px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.08); font-size: 22px; line-height: 1; display: grid; place-items: center; }
.icon.off { opacity: .4; }

/* HUD */
#hud { width: 100%; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 22px; margin: 10px 0 8px; }
.stat { display: flex; flex-direction: column; align-items: center; min-width: 64px; }
.stat small { font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; opacity: .6; }
.stat b { font-size: 22px; font-variant-numeric: tabular-nums; }
.stat.warn b { color: #ff7a7a; }
.bar { flex-basis: 100%; height: 8px; border-radius: 4px; background: rgba(255,255,255,.1); overflow: hidden; max-width: 420px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #3ddc84, #3fa7ff); transition: width .3s; }

/* Board */
#boardWrap { position: relative; flex: 1 1 0; width: 100%; min-height: 0; min-width: 0; }
#board { touch-action: none; display: block; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
#banner { position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%) scale(.6); opacity: 0; pointer-events: none;
  font-size: clamp(26px, 7vw, 44px); font-weight: 800; white-space: nowrap;
  text-shadow: 0 3px 0 rgba(0,0,0,.35), 0 0 24px rgba(255,255,255,.35); }
#banner.show { animation: pop 1.1s ease-out forwards; }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.6); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  30% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(1); }
}

#gameFooter { display: flex; gap: 12px; margin-top: 10px; }
#gameFooter button { padding: 10px 22px; border-radius: 12px; border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.08); font-size: 16px; }
#dirBtn { font-size: 22px !important; padding: 6px 18px !important; }

/* Modal */
#modal { position: fixed; inset: 0; background: rgba(3,12,18,.65); display: grid; place-items: center; z-index: 10; padding: 16px; }
.card { width: min(420px, 100%); max-height: 90%; overflow-y: auto; background: linear-gradient(180deg, #17505a, #0d3440);
  border: 1px solid rgba(255,255,255,.18); border-radius: 20px; padding: 22px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.card h2 { margin: 0 0 12px; font-size: 26px; }
.card .body { font-size: 16px; line-height: 1.5; opacity: .92; }
.card .body p { margin: 0 0 10px; }
.card .body.left { text-align: left; font-size: 14.5px; }
.card .actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.card .actions button { padding: 10px 20px; border-radius: 12px; border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.08); font-size: 16px; font-weight: 600; }
.card .actions button.primary { background: linear-gradient(180deg, #2fc7a6, #1a9480); border-color: transparent; }

/* Landscape phones: HUD becomes a sidebar */
@media (orientation: landscape) and (max-height: 540px) {
  #game { max-width: none; display: grid; grid-template-columns: 180px 1fr; grid-template-rows: auto 1fr auto; column-gap: 12px; }
  #game .topbar { grid-column: 1; grid-row: 1; }
  #hud { grid-column: 1; grid-row: 2; flex-direction: column; justify-content: flex-start; margin: 12px 0; }
  #boardWrap { grid-column: 2; grid-row: 1 / 4; align-self: stretch; justify-self: stretch; }
  #gameFooter { grid-column: 1; grid-row: 3; flex-wrap: wrap; justify-content: center; }
}
