:root {
  color-scheme: dark;
  font-family: "Noto Serif SC", "Songti SC", STSong, serif;
  --paper: #f3ddad;
  --ink: #15231a;
  --red: #b5422f;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #15231a;
}

button { font: inherit; }

#game {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 420px;
  overflow: hidden;
  isolation: isolate;
  cursor: crosshair;
  user-select: none;
  touch-action: none;
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.vignette {
  position: absolute;
  z-index: 2;
  inset: 0;
  background: radial-gradient(circle at 55% 46%, transparent 38%, rgba(5, 12, 8, .2) 78%, rgba(4, 9, 6, .55) 100%);
  pointer-events: none;
}

.topbar {
  position: absolute;
  z-index: 5;
  inset: max(18px, env(safe-area-inset-top)) 22px auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  pointer-events: none;
}

.brand { text-shadow: 0 2px 12px rgba(21, 35, 26, .25); }

.eyebrow {
  margin: 0 0 4px;
  color: rgba(243, 221, 173, .68);
  font: 500 9px/1.2 system-ui, sans-serif;
  letter-spacing: .25em;
}

.mode-mark {
  margin: 7px 0 0;
  color: rgba(210, 232, 185, .54);
  font: 500 9px/1 system-ui, sans-serif;
  letter-spacing: .18em;
}

h1 {
  margin: 0;
  color: var(--paper);
  font-size: clamp(20px, 3vw, 30px);
  font-weight: 600;
  letter-spacing: .16em;
}

.actions { display: flex; gap: 8px; pointer-events: auto; }

.icon-button, .text-button {
  min-height: 38px;
  border: 1px solid rgba(243, 221, 173, .35);
  color: var(--paper);
  background: rgba(17, 30, 22, .42);
  backdrop-filter: blur(8px);
  cursor: pointer;
}

.icon-button { width: 38px; border-radius: 50%; }
.text-button { padding: 0 14px; border-radius: 20px; font-size: 12px; letter-spacing: .1em; }
.icon-button:active, .text-button:active { transform: scale(.96); }

.scoreboard {
  position: absolute;
  z-index: 4;
  top: max(88px, calc(env(safe-area-inset-top) + 80px));
  left: 50%;
  display: flex;
  align-items: flex-end;
  gap: clamp(20px, 6vw, 64px);
  color: var(--paper);
  transform: translateX(-50%);
  text-align: center;
  text-shadow: 0 2px 10px rgba(0, 0, 0, .35);
  white-space: nowrap;
}

.scoreboard div { display: grid; gap: 4px; }
.scoreboard .label { color: rgba(243, 221, 173, .58); font-size: 10px; letter-spacing: .22em; }
.scoreboard strong { font-size: clamp(13px, 2.4vw, 17px); font-weight: 500; letter-spacing: .12em; }
.scoreboard .score-block strong { font: 300 clamp(26px, 5vw, 42px)/1 ui-monospace, monospace; letter-spacing: .06em; }

.online-panel {
  position: absolute;
  z-index: 5;
  top: max(205px, calc(env(safe-area-inset-top) + 195px));
  right: 22px;
  display: flex;
  flex-direction: column;
  width: min(250px, 25vw);
  height: min(360px, calc(100vh - 275px));
  min-height: 190px;
  padding: 14px;
  overflow: hidden;
  color: var(--paper);
  border: 1px solid rgba(243, 221, 173, .2);
  border-radius: 4px;
  background: linear-gradient(145deg, rgba(17, 30, 22, .75), rgba(25, 44, 29, .48));
  box-shadow: 0 14px 40px rgba(6, 16, 10, .18);
  backdrop-filter: blur(10px);
  pointer-events: auto;
}

.online-summary { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.online-summary > div { display: grid; gap: 4px; }
.online-summary .label { color: rgba(243, 221, 173, .55); font-size: 9px; letter-spacing: .16em; }
.online-summary strong { font: 500 14px/1.2 ui-monospace, monospace; letter-spacing: .04em; }
.online-identity { justify-items: end; text-align: right; }
.online-identity > span { display: flex; align-items: center; gap: 7px; }
.online-status, .online-count { font: 500 9px/1 system-ui, sans-serif; font-style: normal; letter-spacing: .08em; }
.online-status { color: #bbd995; }
.online-count { color: rgba(243, 221, 173, .55); }
.online-status.offline { color: #e1ad8d; }

.ranking-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 13px -2px 7px;
  padding-top: 9px;
  border-top: 1px solid rgba(243, 221, 173, .16);
  font-size: 12px;
  letter-spacing: .2em;
}
.ranking-heading small { color: rgba(243, 221, 173, .45); font: 8px/1 system-ui, sans-serif; letter-spacing: .1em; }
.leaderboard {
  display: grid;
  flex: 1;
  align-content: start;
  gap: 3px;
  min-height: 0;
  margin: 0 -7px 0 0;
  padding: 0 7px 0 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: rgba(243, 221, 173, .3) transparent;
  scrollbar-width: thin;
  touch-action: pan-y;
  list-style: none;
  counter-reset: ranking;
}
.leaderboard::-webkit-scrollbar { width: 3px; }
.leaderboard::-webkit-scrollbar-thumb { border-radius: 2px; background: rgba(243, 221, 173, .3); }
.leaderboard li { display: grid; grid-template-columns: 22px 1fr auto; align-items: center; min-height: 19px; color: rgba(243, 221, 173, .72); font: 10px/1.2 system-ui, sans-serif; }
.leaderboard li::before { content: counter(ranking, decimal-leading-zero); counter-increment: ranking; color: rgba(243, 221, 173, .35); font: 9px/1 ui-monospace, monospace; }
.leaderboard li.me { color: #e6f3bd; }
.leaderboard .rank-score { font-family: ui-monospace, monospace; color: rgba(243, 221, 173, .9); }
.leaderboard .ranking-empty { display: block; padding: 8px 0; color: rgba(243, 221, 173, .42); text-align: center; letter-spacing: .08em; }
.leaderboard .ranking-empty::before { content: none; }

.intro {
  position: absolute;
  z-index: 3;
  top: 48%;
  left: 50%;
  width: min(90vw, 560px);
  color: var(--paper);
  text-align: center;
  transform: translate(-50%, -50%);
  text-shadow: 0 3px 18px rgba(13, 28, 19, .65);
  transition: opacity .45s ease, transform .45s ease;
  pointer-events: none;
}

.intro.hidden { opacity: 0; transform: translate(-50%, -54%); }
.intro .seal { display: inline-block; margin: 0 0 16px; padding: 5px 8px; color: #f4c6a6; border: 1px solid rgba(206, 82, 54, .8); background: rgba(145, 45, 31, .7); font-size: 11px; letter-spacing: .28em; }
.intro h2 { margin: 0; font-size: clamp(38px, 9vw, 74px); font-weight: 500; line-height: 1.25; letter-spacing: .12em; }
.intro > p:not(.seal) { margin: 18px 0 0; color: rgba(243, 221, 173, .72); font: 13px/1.6 system-ui, sans-serif; letter-spacing: .08em; }

.gesture { position: relative; width: 180px; height: 38px; margin: 22px auto 0; border-bottom: 1px solid rgba(243, 221, 173, .25); }
.gesture i { position: absolute; left: 0; bottom: -5px; width: 10px; height: 10px; border-radius: 50%; background: var(--paper); box-shadow: 0 0 16px var(--paper); animation: sweep 1.8s ease-in-out infinite; }
@keyframes sweep { 0%, 100% { left: 0; opacity: .2; } 50% { left: 170px; opacity: 1; } }

.combo {
  position: absolute;
  z-index: 5;
  top: 29%;
  left: 50%;
  display: grid;
  place-items: center;
  color: var(--paper);
  font-size: clamp(20px, 4vw, 32px);
  letter-spacing: .18em;
  opacity: 0;
  transform: translate(-50%, 10px) scale(.9);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
}
.combo.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.combo i { width: 52px; height: 2px; margin-top: 6px; background: var(--red); }

.callout {
  position: absolute;
  z-index: 6;
  top: 42%;
  left: 50%;
  color: #fff1c9;
  display: grid;
  justify-items: center;
  gap: 10px;
  width: min(92vw, 760px);
  opacity: 0;
  transform: translate(-50%, -50%) scale(1.35);
  text-shadow: 0 0 22px rgba(255, 230, 173, .7);
  pointer-events: none;
}
.callout strong { font-size: clamp(30px, 7vw, 62px); font-weight: 500; letter-spacing: .25em; }
.callout small { color: rgba(255, 241, 201, .78); font-size: clamp(11px, 2.2vw, 16px); font-weight: 400; letter-spacing: .18em; }
.callout.flash { animation: callout 1.25s ease-out; }
@keyframes callout { 0% { opacity: 0; transform: translate(-50%, -50%) scale(1.35); } 20% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -55%) scale(.95); } }

.whoosh-text {
  position: absolute;
  z-index: 7;
  color: rgba(239, 246, 214, .9);
  font-size: clamp(18px, 4.5vw, 38px);
  font-weight: 600;
  line-height: 1;
  letter-spacing: .08em;
  text-shadow: 0 0 8px rgba(218, 239, 181, .7), 0 2px 8px rgba(10, 25, 15, .75);
  opacity: 0;
  transform: translate(-50%, -50%) scale(.45);
  animation: whoosh-spread .62s cubic-bezier(.16, .72, .3, 1) var(--delay) forwards;
  pointer-events: none;
}

@keyframes whoosh-spread {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.45); filter: blur(2px); }
  18% { opacity: .95; filter: blur(0); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--drift-x)), calc(-50% + var(--drift-y))) scale(var(--scale)); filter: blur(1px); }
}

footer {
  position: absolute;
  z-index: 4;
  right: 22px;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 22px;
  display: flex;
  justify-content: space-between;
  color: rgba(243, 221, 173, .64);
  font-size: 11px;
  letter-spacing: .16em;
  pointer-events: none;
}

footer p { margin: 0; }
.poem { writing-mode: horizontal-tb; }

@media (max-width: 600px) {
  .topbar { inset-inline: 16px; }
  .scoreboard { top: max(82px, calc(env(safe-area-inset-top) + 72px)); gap: 22px; }
  .scoreboard > div:first-child { display: none; }
  .online-panel {
    top: auto;
    right: 16px;
    bottom: calc(env(safe-area-inset-bottom) + 30px);
    left: 16px;
    width: auto;
    height: 112px;
    min-height: 0;
    padding: 9px 11px;
  }
  .online-summary { align-items: center; }
  .online-summary > div:first-child { display: flex; align-items: baseline; gap: 8px; }
  .ranking-heading { margin: 7px 0 4px; padding-top: 6px; }
  .leaderboard { display: grid; grid-auto-flow: row; grid-template-rows: none; grid-auto-columns: auto; gap: 2px; overflow-y: auto; }
  .leaderboard li { grid-template-columns: 18px 1fr auto; }
  .intro { top: 45%; }
  footer { right: 16px; bottom: calc(env(safe-area-inset-bottom) + 10px); left: 16px; }
  .poem { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .gesture i { animation-duration: 3.5s; }
  .callout.flash { animation-duration: .65s; }
  .whoosh-text { animation-duration: .3s; }
}
