:root {
  --navy: #0A1F44;
  --gold: #D4AF37;
  --blue: #4A90C4;
  --light: #F5F7FA;
  --white: #FFFFFF;
  --graphite: #1A1A1A;
  --danger: #C0392B;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow-x: hidden;
  background: var(--navy);
  color: var(--white);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

body.is-playing {
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
}

#app {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(12px + var(--safe-t))
    calc(12px + var(--safe-r))
    calc(12px + var(--safe-b))
    calc(12px + var(--safe-l));
  position: relative;
}

.page-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 18% 12%, rgba(212, 175, 55, 0.12), transparent 34%),
    radial-gradient(circle at 82% 88%, rgba(74, 144, 196, 0.14), transparent 42%),
    linear-gradient(180deg, #08162c 0%, var(--navy) 58%, #0d2244 100%);
  pointer-events: none;
}

.page-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.04;
  background-image:
    linear-gradient(rgba(255,255,255,.5) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.5) 1px, transparent 1px);
  background-size: 48px 48px;
}

.shell {
  width: 100%;
  max-width: 720px;
  height: min(100dvh - 24px - var(--safe-t) - var(--safe-b), 980px);
  position: relative;
  background: linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.03));
  border: 1px solid rgba(212, 175, 55, 0.28);
  border-radius: 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  backdrop-filter: blur(10px);
}

.screen {
  display: none;
  position: absolute;
  inset: 0;
  padding: 28px 22px 24px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow: auto;
  background: linear-gradient(180deg, rgba(19, 40, 79, 0.97), rgba(10, 31, 68, 0.98));
}

.menu-fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

#screen-menu > *:not(.menu-fx) {
  position: relative;
  z-index: 1;
}

.screen.is-active {
  display: flex;
}

.play-screen {
  padding: 0;
  overflow: hidden;
  background: var(--light);
  align-items: stretch;
  justify-content: stretch;
  text-align: left;
}

.play-screen.is-active {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.brand-mark {
  font-size: 42px;
  margin-bottom: 8px;
  filter: drop-shadow(0 6px 12px rgba(0,0,0,.25));
}

.title {
  margin: 0;
  font-size: clamp(26px, 6vw, 42px);
  letter-spacing: 0.08em;
  color: var(--gold);
  text-shadow: 0 2px 0 rgba(0,0,0,.25);
}

.subtitle {
  margin: 10px 0 0;
  font-size: 16px;
  font-weight: 700;
}

.tagline {
  margin: 8px 0 0;
  color: rgba(255,255,255,.78);
  font-size: 14px;
}

.hint {
  margin: 16px 0 22px;
  color: rgba(245,247,250,.88);
  line-height: 1.45;
  max-width: 340px;
}

.greeting {
  margin: 0 0 10px;
  color: var(--gold);
  font-weight: 600;
}

.menu-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 8px;
  max-width: 360px;
  width: 100%;
  appearance: none;
  border: 0;
  background: rgba(255,255,255,0.06);
  border-radius: 14px;
  padding: 8px 10px;
  cursor: pointer;
  color: inherit;
  font: inherit;
  text-align: left;
}

.menu-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--gold);
  background: rgba(255,255,255,.12);
  flex: 0 0 40px;
}

.menu-hello-block {
  text-align: left;
  min-width: 0;
}

.menu-hello {
  margin: 0;
  font-weight: 700;
  color: var(--gold);
  font-size: 14px;
}

.menu-hello-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: rgba(255,255,255,.78);
}

.legal-links {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  gap: 8px 14px;
  justify-content: center;
  align-items: center;
  font-size: 11px;
}

.legal-links a {
  color: rgba(255,255,255,.55);
  text-decoration: underline;
}

.about-text {
  max-width: 360px;
  line-height: 1.5;
  color: rgba(255,255,255,.88);
}

.about-version {
  margin: 8px 0 18px;
  font-size: 12px;
  color: rgba(255,255,255,.55);
}

.board-note {
  font-size: 13px;
  color: rgba(255,255,255,0.72);
  margin: 8px 0 12px;
}

.board-tabs {
  display: flex;
  gap: 6px;
  width: min(100%, 360px);
  margin-bottom: 8px;
}

.board-tabs .btn {
  flex: 1;
  min-height: 40px;
  font-size: 12px;
}

.board-me {
  font-size: 13px;
  color: var(--gold);
  margin: 0 0 10px;
}

.board-list {
  width: min(100%, 360px);
  padding: 8px 12px;
}

.board-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.board-row.is-me {
  background: rgba(212, 175, 55, 0.12);
  margin: 0 -12px;
  padding: 8px 12px;
  border-radius: 8px;
}

.board-pos {
  color: var(--gold);
  font-weight: 700;
}

.board-who {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.board-avatar {
  border-radius: 50%;
  object-fit: cover;
}

.board-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cloud-status,
.merge-hint {
  font-size: 13px;
  color: rgba(255,255,255,0.72);
  margin-top: 12px;
}
  margin: 14px 0 0;
  font-size: 13px;
  color: rgba(255,255,255,.7);
  line-height: 1.45;
}

.legal-body ul {
  padding-left: 18px;
}

.legal-body {
  text-align: left;
  max-width: 420px;
  line-height: 1.55;
  color: rgba(255,255,255,.88);
  font-size: 14px;
}

.legal-page .screen {
  position: relative;
}

.rotate-hint {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 30;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  background: rgba(10, 31, 68, 0.88);
  color: var(--white);
  font-weight: 700;
  pointer-events: none;
}

.debug-panel {
  position: fixed;
  top: calc(8px + var(--safe-t));
  left: calc(8px + var(--safe-l));
  z-index: 25;
  background: rgba(0,0,0,.72);
  color: #9fef9f;
  font: 11px/1.4 ui-monospace, monospace;
  padding: 8px 10px;
  border-radius: 8px;
  pointer-events: none;
}

@media (orientation: landscape) and (max-height: 500px) {
  .rotate-hint {
    display: flex;
  }
}

.community {
  margin-top: 18px;
  font-size: 12px;
  color: rgba(255,255,255,.62);
}

.btn-community {
  width: min(100%, 360px);
  min-height: 40px;
  margin-top: 8px;
  font-size: 13px;
}

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.04em;
  border-radius: 14px;
  padding: 14px 18px;
  min-height: 48px;
  width: min(100%, 360px);
  transition: transform .12s ease, filter .12s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-gold {
  background: linear-gradient(180deg, #e6c65a, var(--gold) 55%, #b8942b);
  color: var(--navy);
  box-shadow: 0 8px 18px rgba(212, 175, 55, 0.28);
}

a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.btn-ghost {
  background: rgba(255,255,255,0.08);
  color: var(--white);
  border: 1px solid rgba(255,255,255,0.16);
}

.btn-play {
  width: min(100%, 360px);
  min-height: 56px;
  font-size: 20px;
  margin: 22px 0 14px;
}

.menu-links {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: min(100%, 360px);
}

.menu-links .btn {
  width: 100%;
  min-height: 44px;
  font-size: 13px;
}

.panel-screen {
  justify-content: flex-start;
  padding-top: 36px;
}

.panel-screen h2 {
  color: var(--gold);
  margin: 0 0 18px;
}

.help-list {
  text-align: left;
  max-width: 420px;
  line-height: 1.55;
  color: rgba(255,255,255,.9);
}

.keys {
  color: rgba(255,255,255,.7);
  font-size: 13px;
}

.card, .go-stats {
  width: min(100%, 420px);
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 18px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.stat-row:last-child {
  border-bottom: 0;
}

.ach-list {
  width: min(100%, 440px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
  text-align: left;
}

.ach {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px;
  border-radius: 14px;
  background: rgba(255,255,255,0.08);
}

.ach.is-off {
  opacity: 0.55;
}

.ach-title {
  font-weight: 700;
}

.ach-hint {
  font-size: 12px;
  color: rgba(255,255,255,.7);
}

.steps {
  display: grid;
  gap: 10px;
  width: min(100%, 420px);
  margin-bottom: 20px;
}

.steps article {
  background: rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 12px;
}

.steps h3 {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hud {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 6px 10px 4px;
  padding-top: calc(6px + var(--safe-t));
  background: rgba(10, 31, 68, 0.94);
  color: var(--white);
  font-size: 12px;
  z-index: 2;
  flex: 0 0 auto;
  max-height: 15%;
}

.hud-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-row span {
  white-space: nowrap;
}

.hud-wide {
  margin-left: auto;
}

.hud-item strong,
.hud-row strong {
  color: var(--gold);
  font-size: 13px;
}

.combo-val {
  font-weight: 800;
  color: var(--gold);
  transform-origin: center;
}

.combo-val.is-fire {
  text-shadow: 0 0 10px rgba(212, 175, 55, 0.7);
  color: #f0d36a;
}

.xp {
  flex: 1;
  height: 5px;
  border-radius: 99px;
  background: rgba(255,255,255,0.12);
  overflow: hidden;
}

.xp-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--blue), var(--gold));
}

.ach-count {
  margin: 0 0 10px;
  color: var(--gold);
  font-weight: 700;
}

.ach.is-on {
  background: rgba(212, 175, 55, 0.16);
  border: 1px solid rgba(212, 175, 55, 0.28);
}

.ach-pop {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%) translateY(-12px);
  width: min(92%, 320px);
  background: rgba(10, 31, 68, 0.94);
  border: 1px solid rgba(212, 175, 55, 0.45);
  border-radius: 14px;
  padding: 10px 14px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  z-index: 12;
  transition: opacity .2s ease, transform .2s ease;
}

.ach-pop.is-active {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.ach-pop-kicker {
  color: var(--gold);
  font-size: 11px;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.ach-pop-title {
  font-weight: 800;
  margin-top: 4px;
}

.ach-pop-hint {
  font-size: 12px;
  color: rgba(255,255,255,.7);
}

.result-card {
  width: min(100%, 240px);
  aspect-ratio: 4 / 5;
  margin: 8px auto 12px;
  padding: 16px 12px;
  border-radius: 16px;
  background: linear-gradient(180deg, #13284f, #0A1F44);
  border: 1px solid rgba(212, 175, 55, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.rc-name {
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--gold);
  font-weight: 700;
}

.rc-score {
  font-size: 22px;
  font-weight: 800;
}

.rc-rank {
  color: var(--gold);
  font-weight: 700;
}

.rc-meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: rgba(255,255,255,.8);
}

.rc-foot {
  margin-top: 8px;
  font-size: 11px;
  color: rgba(255,255,255,.55);
}

.rank-label {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,.65);
}

.rank-title {
  margin: 4px 0 8px;
  color: var(--gold);
  font-weight: 800;
}

.go-modal {
  max-height: min(92%, 720px);
}

.go-modal .result-card {
  max-height: 180px;
}

.ninja-mode #canvas-wrap {
  box-shadow: inset 0 0 40px rgba(212, 175, 55, 0.12);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: rgba(255,255,255,0.1);
  color: var(--white);
  cursor: pointer;
  font-size: 16px;
}

.hud-effects {
  min-height: 0;
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  background: rgba(10, 31, 68, 0.86);
  padding: 0 8px;
}

.chip {
  display: inline-block;
  margin: 4px 0;
  background: rgba(212, 175, 55, 0.2);
  color: var(--gold);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
}

#canvas-wrap {
  flex: 1 1 auto;
  height: 0;
  width: 100%;
  position: relative;
  min-height: 0;
  background: #E7EDF4;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.mobile-controls {
  display: none;
  gap: 12px;
  padding: 10px 12px calc(12px + var(--safe-b));
  background: rgba(10, 31, 68, 0.94);
}

.mobile-controls button {
  flex: 1;
  height: 64px;
  border: 0;
  border-radius: 18px;
  background: rgba(245, 247, 250, 0.14);
  color: var(--white);
  font-size: 28px;
  font-weight: 700;
  touch-action: none;
  user-select: none;
}

.mobile-controls button:active {
  background: rgba(212, 175, 55, 0.35);
}

@media (hover: none), (max-width: 820px) {
  .mobile-controls {
    display: flex;
  }
}

.overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(10, 31, 68, 0.72);
  z-index: 8;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.overlay.is-active {
  display: flex;
}

.modal {
  width: min(100%, 420px);
  max-height: calc(100% - 24px);
  overflow: auto;
  background: linear-gradient(180deg, #13284f, #0A1F44);
  border: 1px solid rgba(212, 175, 55, 0.35);
  border-radius: 20px;
  padding: 22px 18px;
  text-align: center;
  box-shadow: 0 18px 40px rgba(0,0,0,.35);
}

.modal h2 {
  margin: 0 0 10px;
  color: var(--gold);
  letter-spacing: 0.06em;
}

.modal .btn {
  margin-top: 8px;
}

.new-record {
  color: var(--gold);
  font-weight: 800;
}

.go-stats {
  text-align: left;
  line-height: 1.7;
}

.cta, .cta-mini {
  margin: 14px 0 6px;
  font-size: 13px;
  color: rgba(255,255,255,.78);
}

.loader {
  width: min(100%, 280px);
  height: 14px;
  background: rgba(255,255,255,0.12);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}

.loader-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--blue), var(--gold));
  transition: width .12s linear;
}

.loader-caption {
  color: rgba(255,255,255,.8);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  transform: translateX(-50%) translateY(20px);
  background: rgba(10, 31, 68, 0.94);
  color: var(--white);
  border: 1px solid rgba(212, 175, 55, 0.4);
  border-radius: 12px;
  padding: 10px 14px;
  opacity: 0;
  pointer-events: none;
  z-index: 20;
  transition: opacity .2s ease, transform .2s ease;
}

.toast.is-active {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 430px) {
  .hud-wide {
    display: none;
  }
  .title {
    letter-spacing: 0.04em;
  }
  .menu-profile {
    max-width: 100%;
    margin-bottom: 2px;
  }
  .menu-hello {
    font-size: 13px;
  }
  .shell {
    border-radius: 0;
    height: 100dvh;
    max-width: none;
  }
  #app {
    padding: 0;
  }
  .result-card {
    max-height: 140px;
    aspect-ratio: auto;
    width: 100%;
    padding: 10px;
  }
  .go-modal {
    padding: 14px 12px;
  }
}

.menu-streak {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 13px;
  font-weight: 700;
}

.daily-card {
  width: min(100%, 360px);
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(212, 175, 55, 0.28);
  text-align: left;
}

.daily-kicker {
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--gold);
  font-weight: 800;
}

.daily-title, .daily-progress, .daily-reward {
  margin-top: 4px;
  font-size: 13px;
}

.daily-reward {
  color: rgba(255,255,255,.7);
}

.xp-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  overflow: hidden;
  margin: 8px 0;
}

.xp-bar-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--blue), var(--gold));
  transition: width .7s ease;
}

.xp-caption, .go-daily {
  margin: 6px 0 0;
  font-size: 13px;
  color: rgba(255,255,255,.8);
}

.go-xp {
  width: min(100%, 360px);
  margin: 8px auto 10px;
}

.hud-daily {
  font-size: 12px;
  font-weight: 700;
  color: var(--gold);
  transition: transform .2s ease, color .2s ease;
}

.hud-daily.is-flash {
  transform: scale(1.12);
  color: #fff;
}

.ach-filters {
  display: flex;
  gap: 6px;
  width: min(100%, 440px);
  margin-bottom: 12px;
}

.ach-filters .btn {
  min-height: 40px;
  font-size: 12px;
  padding: 8px;
}

.ach-filters .btn.is-on {
  border-color: var(--gold);
  color: var(--gold);
}

.ach-cat {
  width: 100%;
  margin: 12px 0 6px;
  color: var(--gold);
  font-size: 14px;
  text-align: left;
}

.ach-progress {
  margin-top: 4px;
  font-size: 12px;
  color: rgba(255,255,255,.75);
}

.profile-card {
  text-align: left;
}

.profile-head {
  text-align: center;
  margin-bottom: 10px;
}

.profile-avatar {
  width: 64px;
  height: 64px;
  margin-bottom: 8px;
}

.profile-name {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
}

.profile-level {
  font-weight: 700;
  color: var(--gold);
}

.reward-extra {
  color: var(--gold);
  font-weight: 700;
}

#overlay-reward {
  z-index: 12;
}

.debug-tools {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.debug-tools button {
  font: 11px/1.2 ui-monospace, monospace;
  pointer-events: auto;
}

.btn:active,
.icon-btn:active,
.mobile-controls button:active {
  transform: scale(0.96);
  filter: brightness(0.94);
}

.howto-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  width: min(100%, 420px);
  margin-bottom: 14px;
}

.howto-col {
  text-align: left;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
}

.howto-col h3 {
  margin: 0 0 6px;
  font-size: 14px;
}

.howto-col ul {
  margin: 0;
  padding-left: 18px;
  line-height: 1.55;
  font-size: 13px;
}

.howto-good { border-color: rgba(74, 144, 196, 0.45); }
.howto-bad { border-color: rgba(192, 57, 43, 0.45); }
.howto-bonus { border-color: rgba(212, 175, 55, 0.45); }

@media (min-width: 560px) {
  .howto-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.tutorial-hint {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  width: min(92%, 340px);
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(10, 31, 68, 0.82);
  border: 1px solid rgba(212, 175, 55, 0.4);
  text-align: center;
  pointer-events: none;
  z-index: 3;
}

.tutorial-hint-title {
  margin: 0;
  color: var(--gold);
  font-weight: 800;
  letter-spacing: 0.06em;
}

.tutorial-hint-sub {
  margin: 6px 0 0;
  color: var(--light);
  font-size: 13px;
}

.go-score {
  margin: 4px 0 0;
  font-size: 36px;
  font-weight: 800;
  color: var(--white);
}

.go-best {
  margin: 0 0 8px;
  color: rgba(255,255,255,.75);
  font-size: 13px;
}

.btn-details {
  min-height: 40px;
  font-size: 13px;
}

.cta-weak {
  margin-top: 18px;
  font-size: 12px;
  opacity: 0.75;
}

.btn-community-weak {
  min-height: 40px;
  font-size: 12px;
  opacity: 0.85;
  width: min(100%, 280px);
}

#overlay-confirm,
#overlay-tutorial-done {
  z-index: 14;
}

.daily-card.is-done {
  border-color: rgba(46, 139, 87, 0.55);
}

.board-pos.is-medal {
  font-size: 18px;
}

.board-me {
  font-weight: 800;
}

@media (prefers-reduced-motion: reduce) {
  .btn,
  .icon-btn,
  .loader-fill,
  .xp-bar-fill,
  .toast,
  .ach-pop {
    transition: none !important;
    animation: none !important;
  }
}
