:root {
  color-scheme: light;
  font-family: "Arial Rounded MT Bold", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: #183d32;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

body {
  min-height: 100dvh;
  overflow: hidden;
  background: radial-gradient(circle at 50% 45%, #2d6249 0%, #183d32 76%);
}

button {
  font: inherit;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

img {
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

input,
textarea {
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  user-select: text;
}

.app {
  display: grid;
  min-height: 100dvh;
  place-items: center;
}

.screen {
  position: relative;
  width: min(100vw, calc(100dvh * 0.5622189));
  aspect-ratio: 1500 / 2668;
  overflow: hidden;
  isolation: isolate;
  container-type: inline-size;
}

.game-stage {
  background: #b9e586;
  box-shadow: 0 18px 48px rgb(7 37 25 / 46%);
}

.scene-background,
.start-background,
.title-image,
.board-frame,
.timer img,
.image-button img {
  display: block;
  width: 100%;
  height: auto;
}

.scene-background { position: absolute; inset: 0; z-index: -1; }
.start-background { position: absolute; inset: 0; z-index: -1; }

.is-hidden { display: none !important; }

.image-button {
  position: absolute;
  z-index: 5;
  border: 0;
  padding: 0;
  cursor: pointer;
  background: transparent;
  -webkit-tap-highlight-color: transparent;
}

.image-button:focus-visible,
.number-cell:focus-visible,
.restart-button:focus-visible {
  outline: 8px solid #fff6bd;
  outline-offset: 4px;
}

.exit-button { top: 4.15%; left: 4.2%; width: 29.533%; }
.exit-button:active { transform: scale(0.96); }

.start-button { top: 41.3%; left: 3.6%; width: 48.733%; }
.rules-button { top: 53.75%; left: 4.8%; width: 39.133%; }
.settings-button { top: 65.2%; left: 4.4%; width: 35%; }
.leaderboard-button { top: 76.3%; left: 5%; width: 33.533%; }

.start-loading {
  --loading-progress: 8%;
  position: absolute;
  z-index: 6;
  top: 64%;
  left: 50%;
  width: 58%;
  color: #fff8df;
  text-align: center;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity 220ms ease, transform 220ms ease;
}

.start-loading-copy {
  display: block;
  margin-bottom: 2.2cqw;
  font-size: 4.4cqw;
  font-weight: 900;
  line-height: 1;
  -webkit-text-stroke: 0.55cqw #6c401d;
  paint-order: stroke fill;
  text-shadow: 0 0.6cqw 1.2cqw rgb(37 65 37 / 46%);
}

.start-loading-track {
  position: relative;
  height: 7.2cqw;
  overflow: hidden;
  border: 0.7cqw solid #704315;
  border-radius: 999px;
  background: rgb(255 247 215 / 92%);
  box-shadow: 0 0.8cqw 0 rgb(65 40 17 / 24%);
}

.start-loading-track::after {
  position: absolute;
  top: 12%;
  left: 4%;
  width: 92%;
  height: 28%;
  border-radius: 999px;
  background: rgb(255 255 255 / 28%);
  content: "";
}

.start-loading-fill {
  position: absolute;
  inset: 0.8cqw auto 0.8cqw 0.8cqw;
  width: var(--loading-progress);
  max-width: calc(100% - 1.6cqw);
  border-radius: 999px;
  background: linear-gradient(90deg, #80951d, #a8ce33 58%, #e2c82f);
  box-shadow: inset 0 0.5cqw 0 rgb(255 255 255 / 32%);
  transition: width 180ms ease-out;
}

.start-screen.is-loading .image-button,
.start-screen.is-loading .game-copyright {
  opacity: 0;
  pointer-events: none;
  transform: translateY(1.2cqw) scale(0.985);
}

.start-screen.is-ready .start-loading {
  opacity: 0;
  transform: translateX(-50%) translateY(1.2cqw);
}

.start-screen.is-ready .image-button,
.start-screen.is-ready .game-copyright {
  opacity: 1;
  pointer-events: auto;
  transition: opacity 220ms ease, transform 150ms ease;
}

.game-copyright {
  position: absolute;
  z-index: 4;
  left: 0;
  right: 0;
  bottom: 1.4%;
  margin: 0;
  color: rgb(255 255 255 / 92%);
  font-size: 2.6cqw;
  font-weight: 850;
  line-height: 1.2;
  text-align: center;
  text-shadow: 0 0.4cqw 1.2cqw rgb(20 47 34 / 68%);
}

.title-image {
  position: absolute;
  z-index: 2;
  top: 16.1%;
  left: 5.733%;
  width: 88.533%;
  pointer-events: none;
}

.timer {
  position: absolute;
  z-index: 3;
  top: 27.1%;
  left: 29.533%;
  width: 40.933%;
}

.timer-value {
  position: absolute;
  top: 49%;
  left: 0;
  width: 100%;
  color: #80951d;
  font-size: 8cqw;
  font-weight: 900;
  line-height: 0.75;
  letter-spacing: -0.055em;
  text-align: center;
  white-space: nowrap;
}

.timer-clock,
.timer-milliseconds {
  display: inline-grid;
  place-items: center;
  vertical-align: baseline;
}

.timer-milliseconds {
  margin-left: 0.03em;
  font-size: 0.38em;
  letter-spacing: -0.04em;
}

.timer-clock::before,
.timer-clock::after,
.timer-milliseconds::before,
.timer-milliseconds::after {
  grid-area: 1 / 1;
  content: attr(data-value);
  line-height: 0.75;
}

.timer-clock::before,
.timer-milliseconds::before {
  z-index: 0;
  color: #483633;
  -webkit-text-fill-color: #483633;
  -webkit-text-stroke: 0.533cqw #483633;
}

.timer-clock::after,
.timer-milliseconds::after {
  z-index: 1;
  color: #80951d;
  -webkit-text-fill-color: #80951d;
  -webkit-text-stroke: 0 transparent;
}

.board-frame {
  position: absolute;
  z-index: 1;
  top: 36.7%;
  left: 3.467%;
  width: 93.067%;
  pointer-events: none;
}

.number-grid {
  position: absolute;
  z-index: 2;
  top: 38.5%;
  left: 6.667%;
  display: grid;
  width: 86.667%;
  aspect-ratio: 1;
  grid-template-columns: repeat(var(--board-size, 5), 1fr);
  grid-template-rows: repeat(var(--board-size, 5), 1fr);
}

.number-cell {
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  border: 0;
  padding: 0 0 0.035em;
  cursor: pointer;
  background-color: transparent;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
  -webkit-tap-highlight-color: transparent;
  transition: filter 130ms ease, opacity 130ms ease, transform 130ms ease;
}

.number-cell--yellow { background-image: url("./assets/ui/game-scene/cell_yellow.png"); color: #80951d; }
.number-cell--green { background-image: url("./assets/ui/game-scene/cell_green.png"); color: #da9334; }

.number-cell span {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  position: relative;
  font-size: 9.333cqw;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.055em;
  pointer-events: none;
}

.number-cell span::before,
.number-cell span::after {
  grid-area: 1 / 1;
  content: attr(data-number);
  line-height: 1;
}

.number-cell span::before {
  z-index: 0;
  color: #483633;
  -webkit-text-fill-color: #483633;
  -webkit-text-stroke: 0.8cqw #483633;
}

.number-cell span::after {
  z-index: 1;
  color: inherit;
  -webkit-text-fill-color: currentcolor;
  -webkit-text-stroke: 0 transparent;
}

.number-cell:active { transform: scale(0.95); }
.number-cell.is-correct { cursor: default; filter: brightness(1.08) saturate(0.72); opacity: 0.57; transform: scale(0.94); }
.number-cell.is-wrong { animation: shake 260ms ease-in-out; }

.result-modal {
  position: absolute;
  z-index: 12;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 4.2%;
  background: rgb(21 63 41 / 47%);
  backdrop-filter: blur(5px) saturate(0.9);
}

.result-modal.is-hidden { display: none; }

.panel-modal {
  position: absolute;
  z-index: 12;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 7%;
  background: rgb(21 63 41 / 47%);
  backdrop-filter: blur(5px) saturate(0.9);
}

.panel-card {
  display: flex;
  width: 100%;
  min-height: 48%;
  flex-direction: column;
  justify-content: center;
  padding: 7.2cqw 6.4cqw 5.6cqw;
  border: 1.067cqw solid #d98a1f;
  border-radius: 5.467cqw;
  background:
    linear-gradient(135deg, rgb(255 251 225 / 94%), rgb(255 242 201 / 96%)),
    repeating-linear-gradient(0deg, transparent 0 5px, rgb(192 139 49 / 4%) 5px 6px);
  box-shadow:
    inset 0 0 0 0.8cqw #ffe7a9,
    inset 0 0 0 1.25cqw #f1bd65,
    0 1.067cqw 0 #a85f1b,
    0 2.6cqw 4.6cqw rgb(31 50 28 / 40%);
}

.panel-card--rules { min-height: 57%; }
.panel-card--settings { min-height: 53%; }

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2.2cqw;
}

.panel-heading h2 {
  margin: 0;
  color: #704315;
  font-size: 5.333cqw;
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1;
}

.rules-list {
  display: grid;
  gap: 2.267cqw;
  margin: 5.6cqw 0 auto;
  padding: 0;
  color: #754719;
  font-size: 3.733cqw;
  font-weight: 800;
  line-height: 1.42;
  list-style: none;
}

.rules-list li {
  position: relative;
  padding-left: 5.4cqw;
}

.rules-list li::before {
  position: absolute;
  top: 0.15em;
  left: 0;
  display: grid;
  width: 3.4cqw;
  height: 3.4cqw;
  place-items: center;
  border: 0.267cqw solid #d88a26;
  border-radius: 50%;
  background: #ffe07a;
  color: #754719;
  content: "✓";
  font-size: 2.4cqw;
  line-height: 1;
}

.settings-copy {
  margin: 5cqw 0 2.8cqw;
  color: #754719;
  font-size: 3.733cqw;
  font-weight: 900;
  text-align: center;
}

.size-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2cqw;
  margin-bottom: auto;
}

.size-option {
  min-height: 12.8cqw;
  border: 0.4cqw solid #d9a34d;
  border-radius: 2.4cqw;
  background: #fff4ce;
  color: #754719;
  cursor: pointer;
  font-size: 3.6cqw;
  font-weight: 900;
  line-height: 1;
  transition: transform 150ms ease, background 150ms ease, box-shadow 150ms ease;
}

.size-option.is-selected {
  border-color: #58801c;
  background: #9ec72e;
  box-shadow: inset 0 0.65cqw 0 rgb(255 255 255 / 34%), 0 0.6cqw 0 #4e731a;
  color: #fffde4;
  text-shadow: 0 0.267cqw 0 rgb(68 82 18 / 62%);
}

.size-option:active { transform: translateY(0.4cqw); }

.panel-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3.333cqw;
  margin-top: 5cqw;
}

.result-card {
  display: flex;
  flex-direction: column;
  width: 91.6%;
  min-height: 83%;
  padding: 8.4cqw 7.2cqw 6.3cqw;
  border: 1.067cqw solid #d98a1f;
  border-radius: 5.467cqw;
  background:
    linear-gradient(135deg, rgb(255 251 225 / 86%), rgb(255 242 201 / 92%)),
    repeating-linear-gradient(0deg, transparent 0 5px, rgb(192 139 49 / 4%) 5px 6px);
  box-shadow:
    inset 0 0 0 0.8cqw #ffe7a9,
    inset 0 0 0 1.25cqw #f1bd65,
    0 1.067cqw 0 #a85f1b,
    0 2.6cqw 4.6cqw rgb(31 50 28 / 40%);
  color: #483633;
  text-align: center;
}

.result-heading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2.2cqw;
}

.result-heading h2 {
  margin: 0;
  color: #704315;
  font-size: 5.333cqw;
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1;
}

.result-star {
  width: 4.333cqw;
  height: 4.333cqw;
  fill: #ffcf45;
  stroke: #e9821e;
  stroke-linejoin: round;
  stroke-width: 3;
}

.result-time {
  display: flex;
  justify-content: center;
  align-items: baseline;
  margin: 5.2cqw 0 5.067cqw;
  color: #80951d;
  font-size: 12cqw;
  font-weight: 900;
  letter-spacing: -0.055em;
  line-height: 0.8;
  white-space: nowrap;
}

.result-clock,
.result-milliseconds {
  display: inline-grid;
  place-items: center;
}

.result-milliseconds {
  margin-left: 0.03em;
  font-size: 0.48em;
  letter-spacing: -0.04em;
}

.result-clock::before,
.result-clock::after,
.result-milliseconds::before,
.result-milliseconds::after {
  grid-area: 1 / 1;
  content: attr(data-value);
  line-height: 0.8;
}

.result-clock::before,
.result-milliseconds::before {
  z-index: 0;
  color: #483633;
  -webkit-text-fill-color: #483633;
  -webkit-text-stroke: 0.8cqw #483633;
}

.result-clock::after,
.result-milliseconds::after {
  z-index: 1;
  color: #80951d;
  -webkit-text-fill-color: #80951d;
  -webkit-text-stroke: 0 transparent;
}

.result-divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1.6cqw;
  margin: 0 auto;
  width: 92%;
}

.result-divider::before,
.result-divider::after {
  content: "";
  border-top: 0.267cqw dashed #e8bc70;
}

.result-divider svg {
  width: 4.267cqw;
  height: 3.1cqw;
  fill: #9ab62c;
  stroke: #6d8620;
  stroke-linejoin: round;
  stroke-width: 2;
}

.result-message {
  width: 88%;
  margin: 3.2cqw auto;
  border: 0.267cqw solid #edc574;
  border-radius: 3.067cqw;
  padding: 3.2cqw 4.267cqw;
  background: rgb(255 244 207 / 76%);
  color: #754719;
  font-size: 4.133cqw;
  font-weight: 900;
  line-height: 1.48;
  text-align: left;
}

.leaderboard-modal {
  position: absolute;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 6%;
  background: rgb(21 63 41 / 52%);
  backdrop-filter: blur(4px);
}

.leaderboard-card {
  position: relative;
  width: 92%;
  max-height: 82%;
  overflow: auto;
  padding: 7cqw 5.2cqw 5.2cqw;
  border: 1.067cqw solid #d98a1f;
  border-radius: 4cqw;
  background: linear-gradient(145deg, #fffbe1, #ffefbd);
  box-shadow: inset 0 0 0 0.8cqw #ffe7a9, 0 2cqw 4.6cqw rgb(31 50 28 / 40%);
  color: #483633;
}

.leaderboard-close {
  position: absolute;
  top: 2.4cqw;
  right: 2.8cqw;
  width: 7.2cqw;
  height: 7.2cqw;
  border: 0.4cqw solid #d9a34d;
  border-radius: 999px;
  background: #fff4ce;
  color: #754719;
  cursor: pointer;
  font-size: 5cqw;
  font-weight: 900;
  line-height: 1;
}

.leaderboard-heading { justify-content: center; }
.leaderboard-heading h2 { margin: 0; color: #704315; font-size: 5.333cqw; }

.leaderboard-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.6cqw;
  margin: 4cqw 0 2.6cqw;
}

.leaderboard-tab,
.leaderboard-more,
.leaderboard-submit {
  min-height: 8cqw;
  border: 0.4cqw solid #d9a34d;
  border-radius: 999px;
  background: #fff4ce;
  color: #754719;
  cursor: pointer;
  font-weight: 900;
}

.leaderboard-tab.is-selected,
.leaderboard-submit {
  border-color: #58801c;
  background: linear-gradient(#a8ce33, #72a21f);
  color: #fffde4;
}

.leaderboard-status,
.leaderboard-note {
  min-height: 1.4em;
  margin: 0 0 2cqw;
  color: #755a36;
  font-size: 2.8cqw;
  font-weight: 800;
  text-align: center;
}

.leaderboard-list { display: grid; gap: 1.4cqw; margin: 0; padding: 0; list-style: none; }
.leaderboard-item { display: grid; grid-template-columns: 7cqw minmax(0, 1fr) auto; align-items: center; gap: 2cqw; min-height: 9cqw; padding: 1.4cqw 2cqw; border-radius: 2.2cqw; background: rgb(255 255 255 / 68%); font-size: 3.2cqw; font-weight: 900; }
.leaderboard-item:nth-child(1) { background: #fff0ae; }
.leaderboard-item:nth-child(2) { background: #eef0e9; }
.leaderboard-item:nth-child(3) { background: #f3d2aa; }
.leaderboard-rank { display: grid; width: 5.6cqw; height: 5.6cqw; place-items: center; border-radius: 999px; background: #80951d; color: white; }
.leaderboard-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.leaderboard-time { color: #6f861c; font-size: 3.5cqw; }
.leaderboard-empty { padding: 5cqw 2cqw; border-radius: 2cqw; background: rgb(255 255 255 / 55%); color: #755a36; font-size: 3.2cqw; font-weight: 800; text-align: center; }
.leaderboard-more { width: 100%; margin-top: 2cqw; font-size: 3cqw; }

.leaderboard-form { width: 92%; margin: 0 auto 3.2cqw; text-align: left; }
.leaderboard-form label { color: #754719; font-size: 3cqw; font-weight: 900; }
.nickname-row { display: grid; grid-template-columns: minmax(0, 1fr) 22cqw; gap: 1.6cqw; margin-top: 1cqw; }
.nickname-row input { min-width: 0; height: 8.4cqw; border: 0.4cqw solid #d9a34d; border-radius: 2cqw; padding: 0 2cqw; background: #fffdf1; color: #483633; font: inherit; font-size: 3.2cqw; font-weight: 900; }
.nickname-row input:focus { outline: 0.6cqw solid rgb(128 149 29 / 28%); border-color: #80951d; }
.leaderboard-submit { min-height: 8.4cqw; font-size: 3.2cqw; }
.leaderboard-submit:disabled { cursor: default; opacity: 0.65; }
.leaderboard-note { margin-top: 1.2cqw; text-align: left; }
.is-hidden { display: none !important; }

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3.333cqw;
}

.result-button {
  display: inline-flex;
  min-height: 9.6cqw;
  align-items: center;
  justify-content: center;
  gap: 1.2cqw;
  border: 0.533cqw solid;
  border-radius: 999px;
  padding: 1.3cqw 2.2cqw;
  color: #fffde4;
  cursor: pointer;
  font-size: 3.6cqw;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 0.267cqw 0 rgb(68 82 18 / 62%);
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.result-button svg {
  width: 3.733cqw;
  height: 3.733cqw;
  fill: none;
  stroke: currentcolor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 5;
}

.restart-button {
  border-color: #59831c;
  background: linear-gradient(#a8ce33, #72a21f);
  box-shadow: inset 0 0.8cqw 0 rgb(255 255 255 / 36%), 0 0.8cqw 0 #4e731a;
}

.home-button {
  border-color: #d97b0d;
  background: linear-gradient(#ffd54b, #f4a415);
  box-shadow: inset 0 0.8cqw 0 rgb(255 255 255 / 42%), 0 0.8cqw 0 #c86e0b;
  text-shadow: 0 0.267cqw 0 rgb(152 86 12 / 58%);
}

.result-button:active { transform: translateY(0.6cqw); box-shadow: inset 0 0.8cqw 0 rgb(255 255 255 / 28%), 0 0.2cqw 0 rgb(75 69 21 / 70%); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
  .start-loading,
  .start-loading-fill,
  .start-screen.is-ready .image-button,
  .start-screen.is-ready .game-copyright { transition: none; }
}
