:root {
  --ink: #1c2430;
  --muted: #5c5348;
  --paper: #f7f1e5;
  --paper-2: #fffdf8;
  --line: #e4d3b4;
  --sea-0: #1a6284;
  --sea-1: #102c40;
  --wood: #e6c98a;
  --hole: #f4ead6;
  --stroke: #8c6844;
  --vermilion: #e15a32;
  --good: #1f8a62;
  --bad: #c73b3b;
  --shadow: 0 16px 40px rgba(8, 20, 32, 0.28);
  --ui: "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-family: var(--ui);
  color: var(--ink);
}

html[lang="zh-Hans"] {
  --ui: "Noto Sans SC", "PingFang SC", "Noto Sans JP", sans-serif;
}

html[lang="zh-Hant"] {
  --ui: "Noto Sans TC", "PingFang TC", "Noto Sans JP", sans-serif;
}

html[lang="en"] {
  --ui: "Avenir Next", "Segoe UI", "Hiragino Sans", sans-serif;
}

html[lang^="zh"] .home h1,
html[lang^="zh"] .play-title h1,
html[lang^="zh"] .dialog h2 {
  font-family: var(--ui);
  letter-spacing: 0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(1100px 520px at 8% -10%, rgba(255, 255, 255, 0.18), transparent 55%),
    linear-gradient(165deg, var(--sea-0), var(--sea-1) 72%);
}

button, input { font: inherit; color: inherit; }

button { cursor: pointer; }

button:focus-visible, input:focus-visible {
  outline: 3px solid var(--vermilion);
  outline-offset: 2px;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.home {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 72px;
}

.home-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-end;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  letter-spacing: 0.16em;
  font-size: 12px;
  font-weight: 700;
  color: rgba(247, 241, 229, 0.72);
}

.home h1, .play-title h1 {
  font-family: Fraunces, "Iowan Old Style", "Yu Mincho", serif;
  font-weight: 560;
  letter-spacing: -0.03em;
}

.home h1 {
  margin: 0;
  font-size: clamp(48px, 8vw, 84px);
  line-height: 0.95;
  color: var(--paper);
}

.lead {
  max-width: 38rem;
  margin: 14px 0 0;
  color: rgba(247, 241, 229, 0.86);
  font-size: 16px;
  line-height: 1.7;
}

.modes {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.22);
}

.modes button {
  border: 0;
  background: transparent;
  color: var(--paper);
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 700;
}

.modes button[aria-pressed="true"] {
  background: var(--paper);
  color: var(--ink);
}

.home-tools {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.langs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.langs button {
  border-radius: 999px;
  padding: 6px 10px;
  font-weight: 700;
  font-size: 13px;
}

.home .langs button {
  border: 1px solid rgba(247, 241, 229, 0.4);
  background: transparent;
  color: var(--paper);
}

.home .langs button[aria-pressed="true"] {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--paper);
}

.play .langs { margin-top: 10px; }

.play .langs button {
  border: 1px solid var(--line);
  background: var(--paper-2);
}

.play .langs button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.icon-btn, .text-btn, .zoom button {
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.14);
  color: var(--paper);
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 700;
}

.home .icon-btn { color: var(--paper); }

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
  padding: 12px;
  border: 0;
  border-radius: 18px;
  background: var(--paper);
  box-shadow: var(--shadow);
  transition: transform 0.15s ease;
}

.card:hover { transform: translateY(-2px); }

.card svg {
  width: 100%;
  height: 148px;
  background:
    radial-gradient(300px 120px at 50% 0%, rgba(255, 255, 255, 0.2), transparent 60%),
    #1a5674;
  border-radius: 12px;
  display: block;
}

.card h2 {
  margin: 4px 0 0;
  font-size: 22px;
}

.card p { margin: 0; color: var(--muted); line-height: 1.5; }

.card .stat {
  color: var(--ink);
  font-weight: 700;
}

.note {
  margin: 18px 0 0;
  color: rgba(247, 241, 229, 0.62);
  font-size: 12px;
  line-height: 1.6;
}

.home-foot {
  margin: 28px 0 0;
  text-align: center;
}

.home-foot a {
  color: rgba(247, 241, 229, 0.72);
  font-size: 13px;
  text-decoration: none;
}

.home-foot a:hover,
.home-foot a:focus-visible {
  color: var(--paper);
  text-decoration: underline;
}

.play {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  min-height: 0;
  user-select: none;
}

.top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.top .text-btn, .top .icon-btn {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.play-title { min-width: 0; }

.play-title .eyebrow { color: var(--muted); margin: 0; }

.play-title h1 {
  margin: 0;
  font-size: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meter {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: #efe4cf;
  overflow: hidden;
  min-width: 48px;
}

.meter span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--good);
  border-radius: inherit;
}

.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  font-size: 28px;
  min-width: 5ch;
  text-align: right;
}

.timer.danger { color: var(--bad); }

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
}

.board {
  position: relative;
  flex: 1;
  min-width: 0;
  touch-action: none;
  cursor: grab;
  background:
    radial-gradient(900px 420px at 20% 0%, rgba(255, 255, 255, 0.16), transparent 50%),
    linear-gradient(180deg, #1e7498, #143e5c);
}

.board.panning { cursor: grabbing; }

.board.aiming { cursor: crosshair; }

.board svg {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.rim { filter: drop-shadow(0 7px 0 rgba(48, 28, 8, 0.18)); }

.rim path {
  fill: var(--wood);
  stroke: var(--wood);
  stroke-width: 18;
  stroke-linejoin: round;
  stroke-linecap: round;
  fill-rule: evenodd;
}

.hole {
  fill: var(--hole);
  stroke: var(--stroke);
  stroke-width: 1.25px;
  vector-effect: non-scaling-stroke;
  fill-rule: evenodd;
}

.hole.tiny { stroke-width: 3.5px; }

.hole.hot {
  stroke: var(--vermilion);
  stroke-width: 3px;
  filter: brightness(1.12);
}

.hole.bad {
  stroke: var(--bad);
  stroke-width: 3px;
}

.hole.placed { stroke: rgba(255, 252, 245, 0.92); stroke-width: 1px; }

.hole.pulse { animation: pulse 0.45s ease 3; }

@keyframes pulse {
  50% { stroke: var(--vermilion); stroke-width: 4px; filter: brightness(1.25); }
}

.labels text {
  font-family: var(--ui);
  font-weight: 700;
  pointer-events: none;
}

.zoom {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  gap: 6px;
}

.zoom button {
  width: 40px;
  height: 40px;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  border-color: var(--line);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

.zoom .wide { width: auto; padding: 0 12px; }

.tray {
  width: min(360px, 34vw);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--paper);
  border-left: 1px solid var(--line);
}

.tray-head {
  padding: 12px 14px 8px;
}

.tray-head h2 {
  margin: 0;
  font-size: 16px;
}

.tray-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.tray input {
  width: calc(100% - 28px);
  margin: 0 14px 8px;
  border: 1px solid var(--line);
  background: var(--paper-2);
  border-radius: 10px;
  padding: 8px 10px;
}

.tray-grid {
  overflow: auto;
  padding: 4px 12px 16px;
  overscroll-behavior: contain;
  align-content: start;
}

.tray-grid.shapes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
}

.tray-grid.names {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.piece, .chip {
  border: 1px solid var(--line);
  background: var(--paper-2);
  border-radius: 12px;
  touch-action: none;
  padding: 6px;
}

.piece {
  aspect-ratio: 1;
}

.piece svg { width: 100%; height: 100%; display: block; overflow: visible; }

.chip {
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 700;
  line-height: 1.35;
}

.piece.selected, .chip.selected {
  border-color: var(--vermilion);
  box-shadow: 0 0 0 3px rgba(225, 90, 50, 0.28);
}

.piece.lifted, .chip.lifted { opacity: 0.35; }

.piece.shake, .chip.shake { animation: shake 0.28s linear; }

@keyframes shake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.empty-filter {
  margin: 8px 14px;
  color: var(--muted);
  font-size: 13px;
}

.ghost {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  opacity: 0.8;
  filter: drop-shadow(0 12px 10px rgba(0, 0, 0, 0.28));
}

.ghost svg { width: 100%; height: 100%; display: block; overflow: visible; }

.ghost.micro::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  transform: translate(-50%, -50%);
  border: 2px dashed rgba(255, 252, 245, 0.95);
  border-radius: 50%;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.4));
}

.ghost.name {
  width: max-content;
  height: auto;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink);
  font-weight: 700;
  opacity: 1;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.24);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(12, 28, 40, 0.46);
}

.dialog {
  width: min(420px, 100%);
  background: var(--paper);
  border-radius: 22px;
  padding: 26px 24px 20px;
  box-shadow: var(--shadow);
}

.dialog h2 {
  font-family: Fraunces, "Yu Mincho", serif;
  font-size: 40px;
  margin: 0;
}

.dialog p { margin: 8px 0 0; line-height: 1.6; }

.dialog .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.dialog button {
  border: 1px solid var(--line);
  background: var(--paper-2);
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 700;
}

.dialog .primary {
  background: var(--vermilion);
  border-color: var(--vermilion);
  color: white;
}

.tip {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  margin: 0;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.16);
}

@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .home-top { flex-direction: column; align-items: flex-start; }
  .tray { width: min(320px, 42vw); }
}

@media (max-width: 760px) {
  .grid { grid-template-columns: 1fr; }
  .play {
    height: 100svh;
    overflow: hidden;
  }
  .stage { flex-direction: column; overflow: hidden; }
  .board { flex: 1 1 0; min-height: 0; }
  .tray {
    flex: 1 1 0;
    width: auto;
    height: auto;
    max-height: none;
    min-height: 0;
    overflow: hidden;
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tray:has(.shapes) { flex: 0 0 auto; }
  .tray-head { padding: 8px 12px 4px; }
  .tray-head p {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
  }
  .tray-grid { min-height: 0; }
  .tray-grid.names {
    overflow: auto;
    touch-action: pan-y;
  }
  .tray-grid.names .chip { touch-action: pan-y; }
  .tray-grid.shapes {
    display: flex;
    flex: 0 0 auto;
    overflow-x: auto;
    overflow-y: hidden;
    touch-action: pan-x;
  }
  .tray-grid.shapes .piece {
    flex: 0 0 76px;
    height: 76px;
    aspect-ratio: auto;
    touch-action: pan-x;
  }
  .timer { font-size: 18px; min-width: 4.5ch; }
  .meter { display: none; }
  .play-title { flex: 1 1 auto; }
  .play-title .eyebrow { display: none; }
  .play-title h1 { font-size: 16px; }
  .top { gap: 6px; }
  .top .text-btn,
  .top .icon-btn {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 6px 8px;
    font-size: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card, .hole.pulse, .piece.shake, .chip.shake { animation: none; transition: none; }
}
