/* Hugarró: shared look. Warm paper light theme, calm dark theme.
   Baseline: Chrome 80 on old Android. So: no :has, no nesting, no flex gap,
   no aspect-ratio, no inset shorthand. Only transform and opacity animate. */

:root {
  --bg: #F4EFE5;
  --bg2: #EBE3D4;
  --card: #FFFCF6;
  --card2: #F8F2E7;
  --ink: #2A2831;
  --ink2: #6A6470;
  --ink3: #A39DA6;
  --line: #E0D6C4;
  --good: #3F9A58;
  --bad: #CF5E54;
  --star: #F0AE2E;
  --accent: #4F5BD5;
  --on-accent: #fff;
  --shadow: 0 1px 2px rgba(70, 50, 20, .06), 0 6px 18px rgba(70, 50, 20, .07);
  --shadow-lift: 0 4px 10px rgba(70, 50, 20, .10), 0 14px 32px rgba(70, 50, 20, .12);
  --radius: 18px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --ease-back: cubic-bezier(.34, 1.4, .5, 1);
  --top-safe: env(safe-area-inset-top, 0px);
  --bottom-safe: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15141A; --bg2: #1D1C24; --card: #24232C; --card2: #2B2A34;
    --ink: #F1EDE6; --ink2: #ABA5B0; --ink3: #6F6A76; --line: #36343F;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.25);
    --shadow-lift: 0 4px 10px rgba(0,0,0,.35), 0 14px 32px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15141A; --bg2: #1D1C24; --card: #24232C; --card2: #2B2A34;
  --ink: #F1EDE6; --ink2: #ABA5B0; --ink3: #6F6A76; --line: #36343F;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.25);
  --shadow-lift: 0 4px 10px rgba(0,0,0,.35), 0 14px 32px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 17px; height: 100%; }
html.big-text { font-size: 19.5px; }
body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none; user-select: none;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
h1, h2, h3, p { margin: 0; }
.ic { width: 24px; height: 24px; display: block; flex: none; }

#app { position: fixed; top: 0; left: 0; right: 0; bottom: 0; overflow: hidden; }

/* ---------- screens and transitions ---------- */
.screen {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
  will-change: transform, opacity;
}
.screen.enter-fwd { animation: inFwd .34s var(--ease) both; }
.screen.leave-fwd { animation: outFwd .34s var(--ease) both; pointer-events: none; }
.screen.enter-back { animation: inBack .34s var(--ease) both; }
.screen.leave-back { animation: outBack .34s var(--ease) both; pointer-events: none; }
@keyframes inFwd { from { transform: translate3d(34px,0,0); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes outFwd { from { transform: none; opacity: 1; } to { transform: translate3d(-24px,0,0); opacity: 0; } }
@keyframes inBack { from { transform: translate3d(-24px,0,0); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes outBack { from { transform: none; opacity: 1; } to { transform: translate3d(34px,0,0); opacity: 0; } }
html.low-motion .screen { animation-duration: .01s !important; }

.scroll {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px calc(24px + var(--bottom-safe));
}

/* ---------- top bar ---------- */
.topbar {
  flex: none; display: flex; align-items: center;
  padding: calc(8px + var(--top-safe)) 8px 8px;
  min-height: 60px;
}
.topbar .title { flex: 1; min-width: 0; padding: 0 6px; }
.topbar .t1 { font-size: 1.15rem; font-weight: 750; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .t2 { font-size: .82rem; color: var(--ink2); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 46px; height: 46px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink); flex: none;
  transition: transform .15s var(--ease), background-color .15s;
}
.icon-btn:active { transform: scale(.9); background: var(--bg2); }

/* ---------- home ---------- */
.home-head { padding: calc(22px + var(--top-safe)) 20px 6px; display: flex; align-items: flex-end; }
.home-head .brand { flex: 1; }
.brand-name { font-size: 2.1rem; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.brand-sub { color: var(--ink2); margin-top: 6px; font-size: .95rem; }
.home-total { display: flex; align-items: center; color: var(--ink2); font-weight: 650; font-size: .92rem; margin: 10px 20px 2px; }
.home-total .ic { width: 18px; height: 18px; color: var(--star); fill: var(--star); margin-right: 5px; }

.game-grid { display: grid; grid-template-columns: 1fr 1fr; grid-gap: 12px; padding-top: 12px; }
@media (min-width: 620px) { .game-grid { grid-template-columns: 1fr 1fr 1fr; } }
@media (min-width: 900px) { .game-grid { grid-template-columns: 1fr 1fr 1fr 1fr; } }
.gcard {
  position: relative; text-align: left;
  background: var(--card); border-radius: var(--radius);
  padding: 14px 14px 12px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-height: 168px;
  transition: transform .18s var(--ease);
  overflow: hidden;
}
.gcard:active { transform: scale(.965); }
.gcard::before {
  content: ""; position: absolute; left: 0; top: 0; right: 0; height: 4px;
  background: var(--accent); opacity: .85;
}
.gcard .art { width: 54px; height: 54px; margin-bottom: 8px; }
.gcard .gname { font-weight: 750; font-size: 1.04rem; letter-spacing: -.01em; }
.gcard .gtag { color: var(--ink2); font-size: .8rem; margin-top: 2px; line-height: 1.3; flex: 1; }
.gcard .gprog { margin-top: 10px; display: flex; align-items: center; font-size: .76rem; color: var(--ink2); font-weight: 650; }
.bar { height: 5px; border-radius: 3px; background: var(--bg2); flex: 1; margin-left: 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transform-origin: left center; }

/* ---------- level screen ---------- */
.continue-card {
  display: flex; align-items: center; width: 100%;
  background: var(--accent); color: var(--on-accent);
  border-radius: var(--radius); padding: 16px 18px; margin: 6px 0 16px;
  box-shadow: var(--shadow); text-align: left;
  transition: transform .18s var(--ease);
}
.continue-card:active { transform: scale(.97); }
.continue-card .art { width: 50px; height: 50px; background: rgba(255,255,255,.92); border-radius: 14px; padding: 4px; margin-right: 14px; }
.continue-card .cc-t1 { font-size: .82rem; opacity: .85; font-weight: 600; }
.continue-card .cc-t2 { font-size: 1.35rem; font-weight: 800; letter-spacing: -.01em; }
.continue-card .ic { margin-left: auto; width: 30px; height: 30px; }
.chapter-row { display: flex; overflow-x: auto; margin: 0 -16px 12px; padding: 2px 16px 6px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.chapter-row::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 9px 14px; border-radius: 999px; margin-right: 8px;
  background: var(--card); color: var(--ink2); font-weight: 650; font-size: .86rem;
  box-shadow: var(--shadow); transition: transform .15s var(--ease), background-color .2s, color .2s;
}
.chip:active { transform: scale(.94); }
.chip.on { background: var(--accent); color: var(--on-accent); }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); grid-gap: 9px; }
@media (min-width: 560px) { .level-grid { grid-template-columns: repeat(8, 1fr); } }
.lvl {
  position: relative; height: 62px; border-radius: 14px;
  background: var(--card); box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 750; font-size: 1.05rem;
  transition: transform .15s var(--ease);
}
.lvl:active { transform: scale(.92); }
.lvl .stars { margin-top: 3px; }
.lvl .stars .ic { width: 12px; height: 12px; }
.lvl.locked { background: var(--bg2); color: var(--ink3); box-shadow: none; }
.lvl.locked .ic { width: 18px; height: 18px; }
.lvl.current { background: var(--accent); color: var(--on-accent); }
.lvl.current .stars .st .ic { color: rgba(255,255,255,.5); }
.stars { display: inline-flex; }
.stars .st .ic { color: var(--ink3); fill: none; }
.stars .st.on .ic { color: var(--star); fill: var(--star); }

/* ---------- game screen ---------- */
.game-body { flex: 1; position: relative; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.game-status { color: var(--ink2); }
.loading {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--ink2);
}
.spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3.5px solid var(--bg2); border-top-color: var(--accent);
  animation: spin .8s linear infinite; margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* shared toolbar for games */
.tool-row {
  flex: none; display: flex; justify-content: center; align-items: stretch;
  padding: 8px 10px calc(12px + var(--bottom-safe));
}
.tool-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 68px; padding: 8px 6px; margin: 0 4px; border-radius: 14px;
  color: var(--ink2); font-size: .74rem; font-weight: 650;
  transition: transform .15s var(--ease), background-color .15s, color .15s;
}
.tool-btn .ic { width: 26px; height: 26px; margin-bottom: 3px; }
.tool-btn:active { transform: scale(.9); background: var(--bg2); }
.tool-btn.on { color: var(--accent); background: var(--card); box-shadow: var(--shadow); }
.tool-btn[disabled] { opacity: .35; pointer-events: none; }
.tool-btn .badge {
  position: absolute; margin: -30px 0 0 30px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: var(--on-accent); font-size: .68rem; line-height: 18px; text-align: center;
}
.tool-btn { position: relative; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 52px; padding: 0 20px; border-radius: 16px;
  background: var(--bg2); color: var(--ink); font-weight: 700; font-size: 1rem;
  transition: transform .15s var(--ease), background-color .15s;
}
.btn .ic { margin-right: 8px; }
.btn:active { transform: scale(.96); }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.danger { background: var(--bad); color: #fff; }

/* ---------- sheets (dialogs) ---------- */
.scrim {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 50;
  background: rgba(20, 16, 12, 0); display: flex; align-items: flex-end; justify-content: center;
  transition: background-color .28s var(--ease);
}
.scrim.open { background: rgba(20, 16, 12, .42); }
.sheet {
  width: 100%; max-width: 520px; background: var(--card); color: var(--ink);
  border-radius: 26px 26px 0 0; padding: 26px 20px calc(18px + var(--bottom-safe));
  transform: translate3d(0, 100%, 0); transition: transform .34s var(--ease);
  max-height: 88vh; overflow-y: auto;
}
.scrim.open .sheet { transform: none; }
.scrim.closing .sheet { transform: translate3d(0, 100%, 0); }
@media (min-width: 560px) {
  .scrim { align-items: center; }
  .sheet { border-radius: 26px; transform: translate3d(0, 30px, 0) scale(.96); opacity: 0; transition: transform .3s var(--ease), opacity .3s var(--ease); }
  .scrim.open .sheet { transform: none; opacity: 1; }
  .scrim.closing .sheet { transform: translate3d(0, 20px, 0) scale(.97); opacity: 0; }
}
.sheet-title { font-size: 1.4rem; font-weight: 800; letter-spacing: -.02em; }
.sheet-text { color: var(--ink2); margin-top: 8px; line-height: 1.5; }
.sheet-actions { display: flex; margin-top: 22px; }
.sheet-actions .btn { flex: 1; margin-left: 10px; }
.sheet-actions .btn:first-child { margin-left: 0; }
.help-body { line-height: 1.55; color: var(--ink2); margin-top: 10px; }
.help-body p { margin-top: 10px; }
.help-body b { color: var(--ink); }

/* win sheet */
.win { text-align: center; }
.win .win-stars { display: flex; justify-content: center; margin: 6px 0 12px; }
.win .win-stars .ic { width: 58px; height: 58px; margin: 0 4px; color: var(--line); fill: var(--bg2); }
.win .win-stars .st { transform: scale(.4); opacity: .0; }
.win .win-stars .st.show { animation: starPop .5s var(--ease-back) both; }
.win .win-stars .st.on .ic { color: var(--star); fill: var(--star); }
.win .win-stars .st:nth-child(2) .ic { width: 70px; height: 70px; margin-top: -10px; }
@keyframes starPop { from { transform: scale(.3) rotate(-25deg); opacity: 0; } to { transform: none; opacity: 1; } }
.win .win-title { font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; }
.win .win-sub { color: var(--ink2); margin-top: 6px; }
.win-sheet .sheet-actions { flex-wrap: wrap; }
.win-sheet .sheet-actions .btn { flex: 1 1 40%; }
.win-sheet .sheet-actions .btn.primary { flex: 1 1 100%; margin: 0 0 10px; }
.win-sheet .sheet-actions .btn.primary + .btn { margin-left: 0; }

/* ---------- settings ---------- */
.set-group { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-top: 14px; overflow: hidden; }
.set-row { display: flex; align-items: center; padding: 14px 16px; min-height: 62px; border-top: 1px solid var(--line); }
.set-row:first-child { border-top: 0; }
.set-row .lbl { flex: 1; font-weight: 650; }
.set-row .lbl small { display: block; color: var(--ink2); font-weight: 500; font-size: .8rem; margin-top: 2px; }
.switch { width: 54px; height: 32px; border-radius: 16px; background: var(--bg2); position: relative; flex: none; transition: background-color .2s; }
.switch::after { content: ""; position: absolute; left: 3px; top: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .22s var(--ease); }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translate3d(22px, 0, 0); }
.seg { display: flex; background: var(--bg2); border-radius: 12px; padding: 3px; }
.seg button { padding: 8px 12px; border-radius: 9px; font-size: .85rem; font-weight: 650; color: var(--ink2); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
input[type=range] { width: 140px; accent-color: var(--accent); }
.set-note { color: var(--ink2); font-size: .82rem; margin: 18px 4px 0; line-height: 1.5; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--bottom-safe)); z-index: 60;
  transform: translate3d(-50%, 20px, 0); opacity: 0;
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 14px;
  font-weight: 650; font-size: .92rem; max-width: 86vw; text-align: center;
  transition: transform .3s var(--ease), opacity .3s var(--ease); pointer-events: none;
}
.toast.show { transform: translate3d(-50%, 0, 0); opacity: 1; }

/* install hint */
.install-card { margin-top: 18px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; display: flex; align-items: center; }
.install-card .lbl { flex: 1; font-weight: 650; font-size: .92rem; }
.install-card .lbl small { display: block; font-weight: 500; color: var(--ink2); margin-top: 2px; }

html.low-motion *, html.low-motion *::before, html.low-motion *::after { transition-duration: .01s !important; animation-duration: .01s !important; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01s !important; animation-duration: .01s !important; }
}
