:root {
  --blue: #8fd3ff;
  --blue-deep: #4aa9e8;
  --cream: #fff8e8;
  --ink: #11151a;
  --glass: rgba(255,255,255,.38);
  --border: rgba(255,255,255,.72);
  --green: #7dff45;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { background: #9bd8ff; }
body {
  min-height: 100svh;
  overflow-x: hidden;
  overscroll-behavior: none;
  background: linear-gradient(180deg, #9bd8ff 0%, #d9f2ff 100%);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  -webkit-font-smoothing: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
button, canvas { -webkit-tap-highlight-color: transparent; }
.page { width: min(1100px, 100%); margin: 0 auto; padding: 20px 16px 28px; }
.topbar { display:flex; align-items:center; justify-content:space-between; gap:16px; padding: 6px 2px 16px; }
.brand { font-weight: 1000; letter-spacing: .08em; font-size: clamp(20px, 3vw, 30px); }
.tagline { font-size: 12px; opacity: .68; }
.game-shell {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--glass);
  box-shadow: 0 18px 60px rgba(20,80,120,.16), inset 0 1px 0 rgba(255,255,255,.8);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.game-header { display:grid; grid-template-columns: repeat(3, 1fr); gap:8px; padding: 2px 4px 10px; font-size: 13px; }
.game-header > div { padding: 8px 10px; border:1px solid rgba(255,255,255,.55); border-radius: 12px; background: rgba(255,255,255,.42); text-align:center; }
.label { margin-right:6px; opacity:.55; font-size:10px; }
.canvas-wrap { position:relative; width:100%; overflow:hidden; border-radius:16px; background:#8fd3ff; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }
canvas { display:block; width:100%; height:auto; image-rendering: pixelated; image-rendering: crisp-edges; }
.overlay { position:absolute; inset:0; display:grid; place-items:center; background:rgba(12,35,50,.18); transition:opacity .18s ease; }
.overlay.hidden { opacity:0; pointer-events:none; }
.overlay-card { width:min(430px, 86%); padding:24px; border:2px solid rgba(255,255,255,.95); border-radius:20px; background:rgba(255,255,255,.82); box-shadow:0 14px 50px rgba(0,0,0,.14); text-align:center; }
.pixel-title { font-weight:1000; font-size:clamp(22px, 5vw, 40px); letter-spacing:.06em; text-shadow: 3px 3px 0 #b8d8ea; }
.overlay-card p { max-width:340px; margin:12px auto 18px; font-size:13px; line-height:1.5; }
.overlay-card button { min-height:48px; padding:13px 18px; border:0; border-radius:12px; background:#11151a; color:#fff; box-shadow:4px 4px 0 #59a9d9; cursor:pointer; font:900 13px ui-monospace,monospace; }
.overlay-card button:active { transform:translate(2px,2px); box-shadow:2px 2px 0 #59a9d9; }
.overlay-card small { display:block; margin-top:12px; opacity:.6; font-size:10px; }
.controls { display:flex; justify-content:center; flex-wrap:wrap; gap:8px 18px; padding:10px 4px 2px; opacity:.58; font-size:10px; }
.utility-grid { display:grid; grid-template-columns:1.15fr .85fr; gap:12px; margin-top:12px; }
.utility-card { padding:14px; border:1px solid var(--border); border-radius:20px; background:var(--glass); box-shadow:0 12px 40px rgba(20,80,120,.10), inset 0 1px 0 rgba(255,255,255,.7); backdrop-filter:blur(18px); -webkit-backdrop-filter:blur(18px); }
.utility-head { display:flex; align-items:center; justify-content:space-between; margin-bottom:10px; font-size:11px; font-weight:900; letter-spacing:.08em; opacity:.8; }
#boardStatus { font-size:9px; opacity:.65; }
.period-tabs { display:flex; gap:5px; margin:0 0 8px; }
.period-tab { flex:1; border:1px solid rgba(255,255,255,.58); border-radius:8px; padding:6px 4px; background:rgba(255,255,255,.28); color:var(--ink); font:900 8px ui-monospace,monospace; cursor:pointer; }
.period-tab.active { background:#11151a; color:#fff; border-color:#11151a; }
.leaderboard { display:grid; gap:6px; min-height:38px; margin:0; padding:0; list-style:none; }
.leaderboard li { display:grid; grid-template-columns:28px minmax(0,1fr) auto; align-items:center; gap:8px; padding:7px 9px; border:1px solid rgba(255,255,255,.5); border-radius:10px; background:rgba(255,255,255,.34); font-size:11px; }
.leaderboard .rank { opacity:.55; }
.leaderboard .name { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.utility-card p { margin:0 0 12px; font-size:11px; line-height:1.5; opacity:.72; }
.score-form { display:grid; gap:6px; margin-top:10px; }
.score-form label, #scoreStatus { font-size:9px; opacity:.65; }
.score-form > div { display:flex; gap:7px; }
.score-form input { min-width:0; flex:1; padding:9px 10px; border:1px solid rgba(255,255,255,.76); border-radius:9px; outline:none; background:rgba(255,255,255,.62); color:var(--ink); font:800 11px ui-monospace,monospace; text-transform:uppercase; }
.score-form button, .daily-row button { border:0; border-radius:10px; padding:9px 11px; background:#11151a; color:#fff; font:900 10px ui-monospace,monospace; cursor:pointer; box-shadow:3px 3px 0 #59a9d9; }
.score-form button:disabled { cursor:not-allowed; opacity:.45; box-shadow:none; }
.daily-row { display:flex; align-items:center; gap:7px; flex-wrap:wrap; }
.daily-row strong { font-size:20px; }
.daily-row span { margin-right:auto; font-size:9px; opacity:.55; }
.daily-row button:active, .score-form button:active:not(:disabled) { transform:translate(2px,2px); box-shadow:1px 1px 0 #59a9d9; }
.progress-card { margin-top:12px; padding:14px; border:1px solid var(--border); border-radius:20px; background:var(--glass); box-shadow:0 12px 40px rgba(20,80,120,.10), inset 0 1px 0 rgba(255,255,255,.7); backdrop-filter:blur(18px); }
.progress-grid { display:grid; grid-template-columns:1.05fr 1fr .8fr; gap:14px; }
.level-panel { display:flex; align-items:center; gap:12px; }
.level-orb { flex:0 0 62px; height:62px; display:grid; place-content:center; border:3px solid #11151a; border-radius:13px; background:#ffd84a; text-align:center; box-shadow:4px 4px 0 #59a9d9; transform:rotate(-2deg); }
.level-orb span { font-size:8px; font-weight:900; }
.level-orb strong { font-size:25px; line-height:1; }
.xp-panel { flex:1; min-width:0; display:grid; gap:7px; }
.xp-panel > div:first-child { display:flex; justify-content:space-between; gap:8px; font-size:10px; }
.xp-panel > span { font-size:9px; opacity:.65; }
.xp-track { height:8px; overflow:hidden; border:1px solid rgba(17,21,26,.18); border-radius:99px; background:rgba(255,255,255,.52); }
.xp-track i { display:block; width:0; height:100%; background:#7dff45; transition:width .35s ease; }
.mini-title { margin-bottom:7px; font-size:8px; font-weight:900; letter-spacing:.1em; opacity:.58; }
.mission-list { display:grid; gap:5px; font-size:9px; }
.mission { display:grid; grid-template-columns:14px 1fr auto; gap:5px; align-items:center; padding:5px 7px; border-radius:8px; background:rgba(255,255,255,.34); }
.mission.complete { background:rgba(125,255,69,.24); }
.mission b { font-size:9px; }
.badge-list { display:flex; gap:6px; flex-wrap:wrap; }
.pixel-badge, .empty-badge { display:grid; place-items:center; width:34px; height:34px; border:2px solid #11151a; border-radius:7px; background:#ffd84a; font-size:18px; box-shadow:2px 2px 0 #59a9d9; }
.empty-badge { opacity:.25; filter:grayscale(1); }
.achievement-text { margin-top:8px; font-size:8px; line-height:1.4; opacity:.6; }
.run-progress { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-top:12px; padding:14px 18px; border:2px solid #11151a; border-radius:16px; background:#7dff45; box-shadow:5px 5px 0 #11151a; }
.run-progress.hidden { display:none; }
.run-progress > div { display:flex; flex-direction:column; gap:2px; }
.run-progress span { font-size:8px; font-weight:900; letter-spacing:.1em; }
.run-progress strong { font-size:22px; }
.run-progress p { margin:0; color:#11151a; font-size:10px; opacity:.8; text-align:right; }
.run-progress button { border:0; border-radius:10px; padding:10px 12px; background:#11151a; color:#fff; font:900 9px ui-monospace,monospace; white-space:nowrap; }
.card-studio { position:fixed; z-index:30; inset:0; display:grid; place-items:center; padding:18px; overflow:auto; background:rgba(7,25,36,.74); backdrop-filter:blur(12px); }
.card-studio.hidden { display:none; }
.card-studio-panel { width:min(900px,100%); padding:18px; border:2px solid #11151a; border-radius:22px; background:#dff6ff; box-shadow:10px 10px 0 #11151a; }
.card-studio-head { display:flex; align-items:flex-start; justify-content:space-between; gap:15px; }
.card-studio-head span { font-size:8px; font-weight:900; letter-spacing:.12em; opacity:.6; }
.card-studio-head h2 { margin:4px 0 0; font-size:24px; }
.card-studio-head > button { width:36px; height:36px; border:2px solid #11151a; border-radius:9px; background:#fff; font-size:24px; line-height:1; }
.card-type-tabs { display:flex; gap:7px; margin:14px 0; }
.card-type { flex:1; padding:9px; border:1px solid rgba(17,21,26,.24); border-radius:9px; background:rgba(255,255,255,.5); font:900 9px ui-monospace,monospace; }
.card-type.active { background:#11151a; color:#fff; }
.card-studio-grid { display:grid; grid-template-columns:minmax(0, .75fr) minmax(240px, .55fr); gap:18px; align-items:start; }
#shareCardCanvas { width:100%; max-height:62vh; object-fit:contain; border:2px solid #11151a; border-radius:14px; background:#8fd3ff; box-shadow:5px 5px 0 #11151a; }
.share-actions { display:grid; gap:8px; }
.share-actions > span { padding:7px 9px; border-radius:7px; background:#ffd84a; font-size:9px; font-weight:900; text-align:center; }
.share-actions > button, .share-url button { min-height:37px; border:0; border-radius:9px; background:#11151a; color:#fff; font:900 9px ui-monospace,monospace; box-shadow:3px 3px 0 #59a9d9; }
.share-actions > button:nth-of-type(3), .share-actions > button:nth-of-type(4) { background:#229ed9; }
.share-url { display:flex; gap:6px; }
.share-url input { min-width:0; flex:1; padding:8px; border:1px solid rgba(17,21,26,.22); border-radius:8px; background:#fff; font:9px ui-monospace,monospace; }
.share-url button { padding:0 10px; }
#cardStatus { margin:2px 0 0; font-size:8px; line-height:1.4; opacity:.66; }
@media (max-width:600px) {
  .page { width:100%; padding: max(10px, env(safe-area-inset-top)) 8px max(14px, env(safe-area-inset-bottom)); }
  .topbar { padding-bottom:10px; }
  .game-shell { padding:7px; border-radius:18px; }
  .game-header { grid-template-columns:repeat(3, minmax(0,1fr)); gap:5px; padding:2px 2px 7px; font-size:10px; }
  .game-header > div { min-width:0; overflow:hidden; padding:8px 4px; border-radius:10px; }
  .label { display:block; margin:0 0 2px; font-size:8px; }
  .canvas-wrap { border-radius:12px; touch-action:none; }
  .overlay-card { width:min(430px, calc(100% - 24px)); padding:18px 14px; border-radius:16px; }
  .overlay-card p { margin:8px auto 14px; font-size:12px; }
  .overlay-card button { width:100%; font-size:12px; }
  .overlay-card small { font-size:9px; }
  .controls { gap:5px 8px; font-size:8px; line-height:1.35; text-align:center; }
  .tagline { display:none; }
  .utility-grid { grid-template-columns:1fr; }
  .utility-card { padding:11px; border-radius:14px; }
  .leaderboard li { padding:6px 8px; }
  .progress-card { padding:11px; border-radius:14px; }
  .progress-grid { grid-template-columns:1fr; }
  .run-progress { align-items:flex-start; flex-direction:column; }
  .run-progress p { text-align:left; }
  .card-studio { place-items:start center; padding:8px; }
  .card-studio-panel { padding:12px; border-radius:16px; }
  .card-studio-grid { grid-template-columns:1fr 1fr; gap:10px; }
  .card-studio-head h2 { font-size:19px; }
  .share-actions { gap:6px; }
  .share-actions > button { min-height:34px; font-size:8px; }
}
@media (max-width:520px) {
  .card-studio-grid { grid-template-columns:1fr; }
  #shareCardCanvas { width:min(62vw,280px); margin:0 auto; max-height:none; }
}
@media (max-width:380px) {
  .controls span:nth-child(1), .controls span:nth-child(2) { display:none; }
  .brand { font-size:20px; }
}