/* BayadEra styles.
   Layout: one phone-width column (max 480px), sticky sea-blue HUD on top,
   monster strip, then the stage that changes per phase. Bottom sheet for cards.
   One deliberate look (seaside baryo at daytime), the same in light and dark. */

:root {
  --sea-deep: #1e4f6e;
  --sea: #2f7f9e;
  --foam: #e6f3ef;
  --paper: #ffffff;
  --ink: #1d2b3a;
  --ink-soft: #4f6273;
  --line: #c6dcda;
  --gold: #f2b33d;
  --gold-deep: #b97c0c;
  --coral: #e5484d;
  --leaf: #2c8f53;
  --slime: #57c26b;
  --sun: #ffe3a3;

  --font-display: 'Baloo 2', 'Arial Rounded MT Bold', 'Trebuchet MS', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --radius: 18px;
  --shadow: 0 3px 0 rgba(29, 43, 58, 0.18);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--foam);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  position: relative;
}

.screen { min-height: 100vh; min-height: 100dvh; }

h1, h2, h3 { font-family: var(--font-display); line-height: 1.1; text-wrap: balance; margin: 0; }

.num { font-variant-numeric: tabular-nums; }

/* ---------- buttons ---------- */

.btn {
  font: 800 1rem/1.2 var(--font-body);
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  padding: 12px 20px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.08s ease;
}
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn:focus-visible, .icon-btn:focus-visible, .chip:focus-visible, .choice:focus-visible, .step:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--gold); }
.btn-ghost { background: transparent; box-shadow: none; border-style: dashed; }
.btn-big { font-size: 1.1rem; padding: 15px 22px; width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 auto; }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
}

/* ---------- title ---------- */

.title-screen { display: flex; flex-direction: column; }

.title-sky {
  background:
    radial-gradient(circle at 86% 58%, var(--sun) 0 30px, transparent 31px),
    linear-gradient(180deg, var(--sea-deep) 0%, var(--sea) 70%, #66b8c9 100%);
  color: #fff;
  padding-block: 40px 0;
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
  text-align: center;
  position: relative;
  overflow: hidden;
}
.title-sky::after {
  /* waves */
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 34px;
  background: radial-gradient(circle at 20px -6px, transparent 22px, var(--foam) 23px) 0 0 / 40px 34px repeat-x;
}
.eyebrow { text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.72rem; font-weight: 800; opacity: 0.85; margin: 0 0 6px; }
.logo {
  font-size: clamp(3rem, 15vw, 4.4rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #fff;
  text-shadow: 0 3px 0 var(--ink), 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 -2px 0 var(--ink), 0 5px 0 var(--ink);
}
.logo span { color: var(--gold); }
.tagline { font-weight: 700; margin: 6px auto 0; max-width: 26ch; }
.title-hero { width: 170px; margin: 12px auto 0; position: relative; z-index: 1; }
.title-hero .art-mika { animation: bob 2.4s ease-in-out infinite; }

.title-actions {
  display: flex; flex-direction: column; gap: 12px;
  padding-block: 24px 32px;
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
}
.fineprint { font-size: 0.8rem; color: var(--ink-soft); text-align: center; margin: 4px 0 0; }

/* ---------- My Life Mode setup ---------- */

.setup-screen { padding-block: 0 40px; }
.setup-head {
  display: flex; gap: 12px; align-items: center;
  background: var(--sea-deep); color: #fff;
  padding-block: 16px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  border-bottom: 3px solid var(--ink);
}
.setup-head h1 { font-size: 1.6rem; }
.setup-head .eyebrow { margin: 0; color: var(--gold); }
.setup-form {
  display: grid; gap: 14px;
  padding-block: 16px 0;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.setup-intro { margin: 0; font-weight: 700; }
.field-row { display: flex; gap: 10px; flex-wrap: wrap; }
.field { display: grid; gap: 4px; min-width: 0; flex: 1 1 120px; }
.field.grow { flex: 2 1 180px; }
.field label { font-size: 0.74rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); }
.field input, .field select {
  font: 700 1rem var(--font-body);
  color: var(--ink); background: var(--paper);
  border: 2px solid var(--line); border-radius: 10px;
  padding: 9px 10px; width: 100%; min-width: 0;
}
.field input:focus, .field select:focus { outline: 3px solid var(--gold); outline-offset: 1px; border-color: var(--ink); }
.rows { display: grid; gap: 10px; }
.row-card {
  position: relative;
  border: 2px solid var(--line); border-radius: 14px;
  padding: 12px 40px 12px 12px;
  display: flex; flex-wrap: wrap; gap: 8px;
}
.debt-card { border-color: #f0c2c2; background: #fff8f7; }
.row-x {
  position: absolute; top: 8px; right: 8px;
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--ink); background: var(--paper); color: var(--ink);
  font-weight: 800; cursor: pointer;
}
.row-hint { flex-basis: 100%; margin: 0; font-size: 0.8rem; color: var(--ink-soft); }
.class-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.class-card {
  display: grid; gap: 2px; justify-items: center; text-align: center;
  font-family: var(--font-body); color: var(--ink);
  border: 2.5px solid var(--line); border-radius: 14px; background: var(--paper);
  padding: 8px; cursor: pointer;
}
.class-card[aria-pressed='true'] { border-color: var(--ink); background: var(--sun); box-shadow: var(--shadow); }
.class-card:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.class-art { width: 56px; }
.class-name { font-family: var(--font-display); font-weight: 800; font-size: 1.1rem; }
.class-how { font-size: 0.78rem; font-weight: 700; }
.class-real { font-size: 0.72rem; color: var(--ink-soft); }
.summary-panel { background: var(--sun); }
.setup-errors p { margin: 0; color: var(--coral); font-weight: 800; }

/* ---------- intro ---------- */

.intro-screen {
  display: flex; align-items: center;
  padding-block: 24px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: linear-gradient(180deg, var(--sea-deep), var(--sea));
}
.intro-card {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 24px;
  padding: 20px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25);
  width: 100%;
  display: flex; flex-direction: column; gap: 14px;
}
.intro-art { display: flex; justify-content: center; gap: 10px; min-height: 120px; align-items: flex-end; }
.intro-art .art-mika { width: 110px; }
.intro-art .art { width: 72px; }
.intro-card h2 { font-size: 1.6rem; }
.intro-card p { margin: 0; }
.intro-nav { display: flex; justify-content: space-between; align-items: center; }
.dots { display: flex; gap: 6px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); display: block; }
.dots i.on { background: var(--ink); }
.goal-list { margin: 0; padding-left: 1.2em; display: grid; gap: 6px; }

/* ---------- HUD ---------- */

.hud {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 5;
  color: #fff;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,0.05) 0 8px, transparent 8px 16px),
    repeating-linear-gradient(-45deg, rgba(255,255,255,0.05) 0 8px, transparent 8px 16px),
    var(--sea-deep);
  padding-block: 10px 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  border-bottom: 3px solid var(--ink);
  display: grid; gap: 8px;
}
body::before {
  content: ''; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--sea-deep);
}
.hud-top { display: flex; justify-content: space-between; align-items: center; }
.hud-hero { display: flex; gap: 10px; align-items: center; }
.hud-face {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--sun); border: 2.5px solid var(--ink);
  overflow: hidden; display: grid; place-items: center;
}
.hud-face svg { width: 62px; margin-top: 22px; }
.hud-name { font-family: var(--font-display); font-weight: 800; font-size: 1.15rem; line-height: 1; }
.lvl { background: var(--gold); color: var(--ink); border-radius: 999px; padding: 1px 8px; font-size: 0.8rem; margin-left: 4px; border: 2px solid var(--ink); }
.hud-class { font-size: 0.78rem; font-weight: 800; color: var(--gold); margin-top: 3px; }
.hud-date { font-size: 0.78rem; opacity: 0.9; font-weight: 700; }

.stamina { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; font-size: 0.75rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; }
.bar { height: 10px; background: rgba(0, 0, 0, 0.3); border-radius: 999px; overflow: hidden; border: 1.5px solid rgba(0,0,0,0.35); }
.bar-fill { height: 100%; background: var(--slime); border-radius: 999px; transition: width 0.4s ease; }
.bar-fill.low { background: var(--coral); }
.bar-fill.mid { background: var(--gold); }
.stamina-num { font-variant-numeric: tabular-nums; min-width: 2.5ch; text-align: right; }

.purse { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.purse-item { background: rgba(255, 255, 255, 0.12); border-radius: 12px; padding: 5px 8px; display: flex; flex-direction: column; min-width: 0; }
.purse-k { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.85; font-weight: 800; }
.purse-v { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.purse-v::before { content: ''; display: inline-block; width: 0.7em; height: 0.7em; border-radius: 50%; background: var(--gold); border: 1.5px solid var(--gold-deep); margin-right: 4px; vertical-align: -0.02em; }
.purse-v.bump { animation: bump 0.4s ease; }

/* ---------- monsters ---------- */

.monsters {
  display: flex; gap: 8px; overflow-x: auto;
  padding-block: 12px 4px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  scrollbar-width: none;
}
.monster {
  flex: 0 0 auto;
  width: 116px;
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 16px;
  padding: 8px;
  display: grid; grid-template-columns: 32px 1fr; gap: 6px; align-items: center;
}
.monster .art { width: 32px; height: 30px; }
.monster-name { font-weight: 800; font-size: 0.76rem; line-height: 1.1; }
.monster-hp { font-size: 0.74rem; font-variant-numeric: tabular-nums; color: var(--ink-soft); font-weight: 700; }
.monster .bar { grid-column: 1 / -1; height: 8px; background: #f1e4e4; border-color: var(--ink); }
.monster .bar-fill { background: var(--coral); }
.monster.defeated { opacity: 0.55; }
.monster.defeated .monster-hp { color: var(--leaf); }
.monster.hit { animation: shake 0.45s ease; }
.monster.boss .bar-fill { background: #b0835b; }

/* ---------- stage ---------- */

.stage {
  padding-block: 8px 40px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid; gap: 14px;
}
.panel {
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: var(--radius);
  padding: 16px;
  display: grid; gap: 10px;
  min-width: 0;
}
.panel h2 { font-size: 1.45rem; }
.panel h3 { font-size: 1.1rem; }
.muted { color: var(--ink-soft); font-size: 0.9rem; margin: 0; }

.receipt { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 0.92rem; }
.receipt li { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dashed var(--line); padding-block: 4px; }
.receipt li span:first-child { min-width: 0; }
.receipt .amt { font-variant-numeric: tabular-nums; font-weight: 800; white-space: nowrap; }
.k-in .amt, .k-good .amt { color: var(--leaf); }
.k-out .amt, .k-save .amt { color: var(--ink); }
.k-heal .amt, .k-bad .amt { color: var(--coral); }
.k-heal span:first-child::before { content: '+ '; color: var(--coral); font-weight: 800; }

.free-gold {
  display: flex; justify-content: space-between; align-items: baseline;
  background: var(--sun); border: 2.5px solid var(--ink); border-radius: 14px; padding: 10px 14px;
}
.free-gold strong { font-family: var(--font-display); font-size: 1.8rem; font-variant-numeric: tabular-nums; }

/* jars */
.jars { display: grid; gap: 10px; }
.jar {
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  display: grid; gap: 8px;
}
.jar-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.jar-title { font-weight: 800; }
.jar-sub { font-size: 0.78rem; color: var(--ink-soft); }
.jar-amt { font-family: var(--font-display); font-weight: 800; font-size: 1.3rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stepper { display: flex; gap: 6px; }
.step {
  flex: 1;
  font: 800 0.95rem var(--font-body);
  border: 2px solid var(--ink); background: var(--foam); color: var(--ink);
  border-radius: 10px; padding: 8px 0; cursor: pointer;
}
.step:active { background: var(--line); }
.jar-attack { border-color: var(--coral); background: #fff6f5; }
.jar-shield { border-color: var(--sea); background: #f2f9fb; }
.jar-treasure { border-color: var(--gold); background: #fffaf0; }
.jar-pocket { border-style: dashed; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font: 800 0.8rem var(--font-body);
  border: 2px solid var(--ink); background: var(--paper); color: var(--ink);
  border-radius: 999px; padding: 4px 10px; cursor: pointer;
}
.chip[aria-pressed='true'] { background: var(--ink); color: #fff; }

/* cycle scene */
.scene {
  position: relative;
  height: 210px;
  border: 2.5px solid var(--ink);
  border-radius: var(--radius);
  overflow: hidden;
  background:
    radial-gradient(circle at 84% 56%, var(--sun) 0 20px, transparent 21px),
    linear-gradient(180deg, #8fd0e0 0%, #c8ecf0 62%, #f3dfb3 62%, #ecd09a 100%);
}
.scene.night {
  background:
    radial-gradient(circle at 82% 24%, #f4f1d0 0 18px, transparent 19px),
    linear-gradient(180deg, #23345a 0%, #3c5683 62%, #b7a27a 62%, #a48d62 100%);
}
.scene-hero { position: absolute; left: 50%; bottom: 18px; width: 96px; transform: translateX(-50%); }
.scene-hero .art-mika { animation: walk 0.5s ease-in-out infinite alternate; }
.scene.paused .scene-hero .art-mika { animation: none; }
.scene-palm { position: absolute; bottom: 52px; font-size: 54px; line-height: 1; animation: drift 9s linear infinite; }
.calendar {
  position: absolute; left: 12px; top: 12px;
  background: var(--paper); border: 2.5px solid var(--ink); border-radius: 12px;
  text-align: center; overflow: hidden; width: 74px;
}
.calendar-m { background: var(--coral); color: #fff; font-weight: 800; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; padding: 2px 0; }
.calendar-d { font-family: var(--font-display); font-weight: 800; font-size: 1.8rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.calendar-w { font-size: 0.7rem; font-weight: 800; padding-bottom: 3px; color: var(--ink-soft); }
.flavor {
  position: absolute; right: 12px; top: 12px; max-width: calc(100% - 110px);
  background: var(--paper); border: 2px solid var(--ink); border-radius: 12px 12px 2px 12px;
  padding: 6px 10px; font-size: 0.8rem; font-weight: 700;
}
.progress { display: grid; gap: 6px; }
.progress .bar { background: var(--line); border-color: var(--ink); height: 12px; }
.progress .bar-fill { background: var(--sea); }
.progress-label { display: flex; justify-content: space-between; font-size: 0.82rem; font-weight: 800; }

/* ---------- sheet (quest cards) ---------- */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(16, 28, 40, 0.55);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade 0.2s ease;
}
.sheet {
  width: 100%; max-width: 480px;
  max-height: 92vh; overflow-y: auto;
  background: var(--paper);
  border: 3px solid var(--ink); border-bottom: 0;
  border-radius: 26px 26px 0 0;
  padding-block: 18px max(22px, env(safe-area-inset-bottom, 0px));
  padding-left: max(18px, env(safe-area-inset-left, 0px));
  padding-right: max(18px, env(safe-area-inset-right, 0px));
  display: grid; gap: 12px;
  animation: rise 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.card-tag { font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; color: var(--sea); }
.card-head { display: flex; gap: 12px; align-items: center; }
.card-art {
  flex: 0 0 auto; width: 60px; height: 60px; border-radius: 16px;
  background: var(--sun); border: 2.5px solid var(--ink);
  display: grid; place-items: center; font-size: 32px;
}
.sheet h2 { font-size: 1.5rem; }
.sheet p { margin: 0; }
.choices { display: grid; gap: 8px; }
.choice {
  text-align: left;
  font: 800 1rem/1.3 var(--font-body);
  border: 2.5px solid var(--ink); border-radius: 14px;
  background: var(--foam); color: var(--ink);
  padding: 12px 14px; cursor: pointer; box-shadow: var(--shadow);
}
.choice:active { transform: translateY(2px); box-shadow: none; }
.choice:disabled { opacity: 0.5; cursor: not-allowed; }
.choice small { display: block; font-weight: 700; color: var(--coral); font-size: 0.78rem; margin-top: 2px; }
.lesson {
  background: #fff6dc; border: 2px dashed var(--gold-deep); border-radius: 14px; padding: 10px 12px;
}
.lesson b { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--gold-deep); }

/* ---------- end screen ---------- */

.stars { display: flex; justify-content: center; gap: 6px; font-size: 2.6rem; line-height: 1; }
.stars .off { filter: grayscale(1); opacity: 0.35; }
.end-title { text-align: center; font-size: 2rem; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { border: 2px solid var(--line); border-radius: 12px; padding: 8px 10px; min-width: 0; }
.stat-k { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 800; color: var(--ink-soft); }
.stat-v { font-family: var(--font-display); font-weight: 800; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.stat.bad .stat-v { color: var(--coral); }
.stat.good .stat-v { color: var(--leaf); }
.history { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.history li { border-bottom: 1px dashed var(--line); padding-bottom: 8px; font-size: 0.9rem; }
.history b { display: block; }
.history .h-lesson { color: var(--ink-soft); }
details summary { cursor: pointer; font-weight: 800; }

/* ---------- toasts ---------- */

.toasts {
  position: fixed; left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
  z-index: 30; display: grid; gap: 8px; justify-items: center; pointer-events: none;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.toast {
  background: var(--gold); color: var(--ink);
  border: 2.5px solid var(--ink); border-radius: 999px;
  padding: 8px 16px; font-weight: 800; box-shadow: var(--shadow);
  animation: pop 2.8s ease forwards;
}

/* ---------- motion ---------- */

@keyframes bob { 50% { transform: translateY(-6px); } }
@keyframes walk { from { transform: translateY(0) rotate(-2deg); } to { transform: translateY(-5px) rotate(2deg); } }
@keyframes drift { from { left: 110%; } to { left: -20%; } }
@keyframes shake { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }
@keyframes bump { 50% { transform: scale(1.12); } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(40%); opacity: 0.4; } }
@keyframes pop {
  0% { transform: translateY(-20px); opacity: 0; }
  10%, 85% { transform: none; opacity: 1; }
  100% { transform: translateY(-10px); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .toast { opacity: 1; }
}