:root {
  color-scheme: dark;
  --ink: #f3eee5;
  --muted: #9e9d94;
  --cream: #111310;
  --paper: #191b17;
  --accent: #ff6b42;
  --accent-dark: #ff7b58;
  --line: rgba(255, 255, 255, 0.1);
  font-family: "Manrope", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; }
body { color: var(--ink); background: var(--cream); user-select: none; }
button, input { font: inherit; }
button { color: inherit; }

.app-shell {
  height: 100svh;
  min-height: 100svh;
  overflow: hidden;
  display: grid;
  grid-template-rows: 72px minmax(0, 1fr) 82px;
  background:
    radial-gradient(circle at 14% 20%, rgba(255, 255, 255, .055) 0 7%, transparent 30%),
    linear-gradient(135deg, #151713, #0e100d);
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: max(10px, env(safe-area-inset-top)) clamp(16px, 4vw, 40px) 8px;
  border-bottom: 1px solid var(--line);
}

.brand { display: inline-flex; align-items: center; gap: 10px; border: 0; background: none; padding: 4px; font-family: "Unbounded", sans-serif; font-size: clamp(15px, 2vw, 21px); cursor: pointer; justify-self: start; }
.brand-mark { width: 25px; height: 26px; display: flex; align-items: end; gap: 2px; transform: skew(-8deg); }
.brand-mark i { flex: 1; border-radius: 4px 4px 2px 2px; }
.brand-mark i:nth-child(1) { height: 64%; background: #f1b92e; }
.brand-mark i:nth-child(2) { height: 96%; background: #ff6740; }
.brand-mark i:nth-child(3) { height: 76%; background: #5dbaa8; }

.level-chip { display: flex; align-items: baseline; gap: 5px; letter-spacing: .04em; }
.level-chip > span:not(.hard-badge) { font-size: 10px; font-weight: 800; color: var(--muted); margin-right: 5px; }
.level-chip strong { font-family: "Unbounded", sans-serif; font-size: 20px; }
.level-chip em { font-style: normal; font-size: 12px; color: var(--muted); }
.level-chip .hard-badge { display: inline-flex; align-items: center; margin-left: 7px; padding: 4px 7px; border: 1px solid rgba(255,107,66,.42); border-radius: 999px; color: var(--accent); background: rgba(255,107,66,.1); font-size: 9px; font-weight: 800; letter-spacing: .09em; }
.level-chip .hard-badge[hidden] { display: none; }
.top-actions { display: flex; align-items: center; gap: 8px; justify-self: end; }
.icon-button, .avatar-button, .close-button { border: 0; cursor: pointer; display: grid; place-items: center; }
.icon-button { width: 40px; height: 40px; border-radius: 50%; background: transparent; font-size: 19px; }
.icon-button:hover { background: rgba(255, 255, 255, .07); }
.avatar-button { width: 38px; height: 38px; border-radius: 50%; background: var(--ink); color: #171914; font-weight: 800; }

.game-stage { min-width: 0; min-height: 0; position: relative; overflow: hidden; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; min-width: 0; min-height: 0; display: block; touch-action: manipulation; }
.game-hint { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); font-size: 12px; font-weight: 700; color: var(--muted); pointer-events: none; transition: opacity .2s; }

.controls { display: flex; justify-content: center; align-items: center; gap: clamp(10px, 3vw, 20px); padding: 10px 16px max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.control-button, .primary-button { border: 0; min-width: 88px; height: 48px; border-radius: 24px; cursor: pointer; font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; gap: 7px; }
.control-button { background: rgba(255, 255, 255, .075); }
.control-button:disabled { opacity: .35; cursor: default; }
.control-button span, .primary-button span { font-size: 20px; line-height: 1; }
.primary-button { min-width: 124px; background: var(--ink); color: #171914; box-shadow: 0 9px 26px rgba(0, 0, 0, .34); }

.entry-screen { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; overflow: auto; padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom)); background: radial-gradient(circle at 50% 18%, rgba(255,107,66,.10), transparent 33%), repeating-linear-gradient(90deg, transparent 0 94px, rgba(255,255,255,.025) 95px 96px), var(--paper); transition: opacity .55s ease, visibility .55s; }
.entry-screen.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.entry-form { width: min(520px, 100%); padding: clamp(24px, 6vw, 64px); }
.eyebrow { margin: 0 0 10px; color: var(--accent-dark); font-size: 10px; font-weight: 800; letter-spacing: .18em; }
.entry-form h1 { margin: 0; font: 700 clamp(36px, 5vw, 68px)/1.03 "Unbounded", sans-serif; letter-spacing: -.05em; }
.entry-copy { max-width: 440px; margin: 24px 0 30px; color: var(--muted); line-height: 1.65; }
label { display: block; margin: 14px 0; }
label > span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 11px; font-weight: 800; }
input { width: 100%; border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; color: var(--ink); background: #22241f; outline: none; user-select: text; }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,107,66,.14); }
.form-error { min-height: 19px; color: #c94034; margin: 4px 0; font-size: 12px; }
.entry-button, .secondary-button { border: 0; border-radius: 14px; min-height: 52px; padding: 0 20px; background: var(--accent); color: white; font-weight: 800; cursor: pointer; }
.entry-button { width: 100%; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 10px 24px rgba(216,76,40,.22); }
.entry-button b { font-size: 21px; }
.entry-form small { display: block; color: var(--muted); text-align: center; margin-top: 14px; }

.sheet, .win-dialog { border: 1px solid var(--line); color: var(--ink); background: var(--paper); box-shadow: 0 24px 80px rgba(0, 0, 0, .52); }
.sheet::backdrop, .win-dialog::backdrop { background: rgba(0,0,0,.62); backdrop-filter: blur(7px); }
.sheet { width: min(520px, calc(100% - 24px)); max-height: min(720px, calc(100% - 24px)); border-radius: 28px; padding: 24px; }
.sheet[open], .win-dialog[open] { animation: dialog-in .28s cubic-bezier(.2,.8,.2,1); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(18px) scale(.97); } }
.sheet-head { display: flex; justify-content: space-between; align-items: start; border-bottom: 1px solid var(--line); padding-bottom: 18px; }
.sheet h2, .win-dialog h2 { margin: 0; font: 700 27px/1.1 "Unbounded", sans-serif; }
.close-button { width: 38px; height: 38px; background: #292b25; border-radius: 50%; font-size: 25px; }
.leader-list { margin-top: 10px; overflow: auto; max-height: 500px; }
.leader-row { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px; padding: 13px 4px; border-bottom: 1px solid var(--line); }
.leader-row .rank { color: var(--muted); font-weight: 800; text-align: center; }
.leader-row:nth-child(-n+3) .rank { color: var(--accent-dark); }
.leader-row strong { font-size: 14px; }
.leader-row span:last-child { color: var(--muted); font-size: 12px; }
.my-rank { margin: 16px 0 0; text-align: center; color: var(--muted); font-size: 12px; }
.profile-progress { display: flex; align-items: baseline; gap: 12px; padding: 30px 0 16px; }
.profile-progress strong { font: 700 52px "Unbounded", sans-serif; color: var(--accent-dark); }
.profile-progress span { color: var(--muted); }
.nickname-form { border-top: 1px solid var(--line); padding-top: 16px; }
.secondary-button { width: 100%; }
.shop-placeholder { min-height: 260px; display: grid; place-items: center; align-content: center; gap: 12px; text-align: center; }
.shop-placeholder > span { width: 72px; height: 72px; display: grid; place-items: center; border-radius: 24px; color: var(--accent); background: rgba(255,107,66,.11); font-size: 30px; }
.shop-placeholder strong { font: 700 18px/1.25 "Unbounded", sans-serif; }
.shop-placeholder p { max-width: 330px; margin: 0; color: var(--muted); line-height: 1.6; }

.win-dialog { width: min(390px, calc(100% - 32px)); border-radius: 28px; padding: 32px; text-align: center; }
.win-seal { width: 70px; height: 70px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 20px; color: white; background: #58aa78; font-size: 35px; box-shadow: 0 9px 24px #58aa784c; }
.win-dialog p:not(.eyebrow) { color: var(--muted); }
.win-dialog .entry-button { margin-top: 22px; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: 98px; transform: translate(-50%, 20px); opacity: 0; background: #f3eee5; color: #171914; padding: 11px 16px; border-radius: 20px; font-size: 12px; pointer-events: none; transition: .25s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
  .app-shell { grid-template-rows: 66px minmax(0, 1fr) 76px; }
  .entry-screen { padding-inline: 0; }
  .entry-form { padding: 28px 24px; }
  .entry-form h1 { font-size: clamp(32px, 10vw, 44px); }
  .entry-copy { margin: 14px 0 16px; font-size: 13px; }
  .entry-form label { margin: 9px 0; }
  .entry-form small { font-size: 10px; }
  .level-chip > span:not(.hard-badge) { display: none; }
  .topbar { padding-inline: 14px; }
  .brand { font-size: 14px; }
  .brand-mark { width: 19px; height: 21px; }
  .icon-button { width: 36px; }
}

@media (max-height: 670px) and (max-width: 760px) {
  .entry-form h1 { font-size: 31px; }
  .entry-copy { margin-block: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
