:root {
  --bg: #f4efe6;
  --surface: #fffdf8;
  --text: #2a2522;
  --muted: #7a716a;
  --line: #e2d9cc;
  --accent: #d93a2b;
  --accent-text: #fff;
  --exp: #3b82c4;
  --green: #2f9e57;
  --egg: #f7f0dc;
  --egg-spot: #9fcf8f;
  --radius: 14px;
  /* the grades of a completion, from the accent: a light hit, a deep super effective, the full accent for a critical hit */
  --grade-hit: color-mix(in srgb, var(--accent) 35%, #fff);
  --grade-super: color-mix(in srgb, var(--accent) 62%, #000);
  --grade-critical: var(--accent);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a19;
    --surface: #282523;
    --text: #f1ebe4;
    --muted: #a59c94;
    --line: #3d3835;
    --accent: #e8513f;
    --exp: #5aa2e0;
    --green: #3fb86b;
    --egg: #e9e1c9;
    --egg-spot: #86b877;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

main {
  max-width: 900px; margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left));
}
h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h2 small { color: var(--muted); font-weight: normal; }
small { color: var(--muted); }

button {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .5rem .9rem;
  cursor: pointer;
}
button:disabled { opacity: .55; cursor: default; }
/* touch: no grey tap flash, no double-tap zoom delay, a little press feedback instead */
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:not(:disabled):active { transform: scale(.97); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
button.primary small { color: inherit; opacity: .85; }
button.big { width: 100%; padding: .8rem; font-size: 1.05rem; }

input:not([type=radio]), select {
  font: inherit;
  width: 100%;
  padding: .55rem .7rem;
  margin-top: .25rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

form { display: grid; gap: .9rem; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: .5rem .8rem; margin: 0; }
legend { color: var(--muted); font-size: .9rem; padding: 0 .3rem; }
.radio { display: block; padding: .15rem 0; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.narrow { max-width: 420px; margin: 10vh auto 0; }
.hint { color: var(--muted); font-size: .9rem; }
.loading, .error { text-align: center; margin-top: 20vh; color: var(--muted); }

.sprite { image-rendering: pixelated; width: 72px; height: 72px; object-fit: contain; }
.sprite.big { width: 112px; height: 112px; }
.sprite.small { width: 40px; height: 40px; vertical-align: middle; }
.item-icon { image-rendering: pixelated; width: 30px; height: 30px; vertical-align: middle; }

/* debug */
#debug-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .4rem;
  padding: .5rem 16px; background: #fde68a; color: #422006; font-size: .9rem;
}
#debug-bar[hidden] { display: none; }
#debug-bar button { padding: .25rem .6rem; background: #fffbeb; border-color: #f59e0b; color: inherit; }
.debug-date { font-variant-numeric: tabular-nums; margin-right: .3rem; }

/* home */
.top {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--accent); color: var(--accent-text);
  border-radius: var(--radius); padding: .7rem 1rem; font-weight: 600;
}
.money { font-variant-numeric: tabular-nums; }
.top { margin-bottom: 1rem; gap: .5rem; }
.player { display: flex; align-items: center; gap: .4rem; min-width: 0; }
.who { display: grid; line-height: 1.2; min-width: 0; }
.who .money { font-size: .8rem; font-weight: 500; opacity: .85; }
.who .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .gear { float: none; margin-left: -.3rem; color: inherit; opacity: .8; }
.top .gear:hover { opacity: 1; }

/* main menu: icons in the title bar */
.menu { display: flex; gap: .15rem; flex-shrink: 0; }
.icon-button {
  position: relative; border: none; background: none; color: inherit; line-height: 0;
  padding: .35rem; border-radius: 10px;
}
.icon-button:hover { background: rgba(255, 255, 255, .15); }
.icon-button svg {
  width: 24px; height: 24px;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.icon-button .count {
  position: absolute; top: 0; right: -2px; min-width: 1rem; height: 1rem; padding: 0 .25rem;
  border-radius: .5rem; background: var(--accent-text); color: var(--accent);
  font-size: .65rem; font-weight: 700; line-height: 1rem;
}

.field { display: grid; grid-template-columns: 180px 1fr; gap: 1rem; align-items: start; }
.team { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; }

.card {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: .1rem;
  min-height: 170px; padding: .7rem .5rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  text-align: center;
}
.card.empty { border-style: dashed; background: transparent; }
.card.add { justify-content: center; width: 100%; color: var(--muted); }
.hatch .card { width: 100%; }
.nick { font-weight: 600; }
.gender.male { color: #4a8fe0; }
.gender.female { color: #e0559a; }
.habit { font-size: .85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.lv { font-size: .8rem; color: var(--muted); }

/* Type chips in the colors of the games, the same in light and dark mode. */
.types { display: flex; gap: .3rem; justify-content: center; flex-wrap: wrap; margin: .2rem 0; }
.type {
  font-size: .72rem; font-weight: 700; line-height: 1.6; letter-spacing: .03em; text-transform: uppercase;
  padding: 0 .55rem; border-radius: 999px; color: #fff; background: #888; text-shadow: 0 1px 1px rgb(0 0 0 / .3);
}
.type-normal { background: #a8a77a; }
.type-fire { background: #ee8130; }
.type-water { background: #6390f0; }
.type-electric { background: #f7d02c; }
.type-grass { background: #7ac74c; }
.type-ice { background: #96d9d6; }
.type-fighting { background: #c22e28; }
.type-poison { background: #a33ea1; }
.type-ground { background: #e2bf65; }
.type-flying { background: #a98ff3; }
.type-psychic { background: #f95587; }
.type-bug { background: #a6b91a; }
.type-rock { background: #b6a136; }
.type-ghost { background: #735797; }
.type-dragon { background: #6f35fc; }
.type-dark { background: #705746; }
.type-steel { background: #b7b7ce; }
.type-fairy { background: #d685ad; }

.bar { display: block; width: 80%; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--exp); }
.bar.wide { width: 100%; margin: .3rem 0 .6rem; }

.bubble {
  position: absolute; min-width: 1.5rem; height: 1.5rem; padding: 0 .4rem;
  border-radius: .75rem; color: #fff; font-size: .8rem; font-weight: 700;
  display: grid; place-items: center;
}
.bubble.red { top: -6px; right: -6px; background: var(--accent); }
.bubble.green { bottom: -6px; left: -6px; background: var(--green); }
.bubble.dot { min-width: 0; width: 1.15rem; height: 1.15rem; padding: 0; top: -5px; right: -5px; box-shadow: 0 0 0 2px var(--surface); }
.evo-hint { position: absolute; top: 4px; left: 6px; }
.held { position: absolute; bottom: 4px; right: 4px; line-height: 0; }
.held .item-icon { width: 22px; height: 22px; }

.egg {
  position: relative; display: grid; place-items: center;
  width: 70px; height: 88px; margin: .2rem 0 .4rem;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background:
    radial-gradient(circle at 30% 30%, var(--egg-spot) 0 9px, transparent 10px),
    radial-gradient(circle at 70% 60%, var(--egg-spot) 0 7px, transparent 8px),
    radial-gradient(circle at 40% 80%, var(--egg-spot) 0 6px, transparent 7px),
    var(--egg);
  box-shadow: inset -6px -8px 0 rgba(0, 0, 0, .08);
}
.egg.big { width: 100px; height: 126px; margin: 0 auto .5rem; }
.egg .inside { width: 56px; height: 56px; opacity: .45; filter: grayscale(.3); }

/* dialog */
dialog {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  padding: 20px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
/* the main action stays reachable at the bottom of long views */
.detail [data-action=exec] { position: sticky; bottom: 0; z-index: 1; box-shadow: 0 -10px 10px -2px var(--surface); }
.close { float: right; border: none; background: none; font-size: 1.5rem; line-height: 1; padding: 0 .3rem; }
.gear { float: left; border: none; background: none; padding: .15rem; color: var(--muted); line-height: 0; }
.gear:hover { color: var(--text); }
.gear svg {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.chosen label { flex: 1; }

.detail { text-align: center; display: grid; gap: .4rem; justify-items: center; }
.detail p { margin: 0; }
.detail form { width: 100%; }
.species { color: var(--muted); font-weight: 400; }
.detail h2 .level { color: var(--muted); font-size: .8em; font-weight: 600; white-space: nowrap; }
.habit-title { font-size: 1.1rem; font-weight: 600; }
.tags { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: center; }
.tag { font-size: .8rem; padding: .1rem .55rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); }
.evolutions { display: grid; gap: .4rem; width: 100%; margin-top: .4rem; }

/* completion: the four grades, or a count */
.grades { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; width: 100%; }
.grades button { display: grid; align-content: center; gap: .1rem; padding: .7rem .5rem; font-weight: 600; }
.grades small { font-weight: 400; }
.grades .grade-hit { background: var(--grade-hit); color: #2a2522; border-color: transparent; }
.grades .grade-super { background: var(--grade-super); color: #fff; border-color: transparent; }
.grades .grade-critical { background: var(--grade-critical); color: #fff; border-color: transparent; }
.grades .grade-hit small, .grades .grade-super small, .grades .grade-critical small { color: inherit; opacity: .8; }
.count-form { gap: .5rem; text-align: left; }
.count-input { display: flex; align-items: center; gap: .5rem; }
.count-input input { width: 7rem; }
.count-form .hint { margin: 0; }

/* habit form: goal or limit, only for the counted types */
.count-fields { display: none; grid-template-columns: 1fr 1fr; gap: .6rem; margin-top: .4rem; }
fieldset:has([value=maximize]:checked, [value=limit]:checked) .count-fields { display: grid; }
.for-limit, fieldset:has([value=limit]:checked) .for-maximize { display: none; }
fieldset:has([value=limit]:checked) .for-limit { display: inline; }
.box-slot { display: grid; gap: .3rem; }
.box-slot .move { padding: .3rem .4rem; font-size: .85rem; }

.tabs { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .8rem; }
.tabs .active { background: var(--text); color: var(--surface); }
.detail .tabs { margin: .3rem 0 .2rem; }

/* Base stats: name, value, bar; the bar grows in when the tab opens. */
.stats {
  display: grid; grid-template-columns: auto auto 1fr; align-items: center; gap: .45rem .7rem;
  width: 100%; max-width: 360px; text-align: left; font-size: .9rem;
}
.stat-name { color: var(--muted); }
.stat-value { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.stat-name.total, .stat-value.total { padding-top: .35rem; border-top: 1px solid var(--line); }
.stat-name.total { color: var(--text); font-weight: 600; }
.stat-bar { display: block; height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; }
.stat-bar > span { display: block; height: 100%; border-radius: 5px; animation: stat-grow .5s ease-out backwards; }
@keyframes stat-grow { from { width: 0; } }
@media (prefers-reduced-motion: reduce) { .stat-bar > span { animation: none; } }
.stat-0 { background: #f34444; }
.stat-1 { background: #ff7f0f; }
.stat-2 { background: #ffdd57; }
.stat-3 { background: #a0e515; }
.stat-4 { background: #23cd5e; }
.stat-5 { background: #00c2b8; }
.search { margin-bottom: .8rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: .5rem; }
.pick { display: flex; flex-direction: column; align-items: center; padding: .4rem; font-size: .9rem; }
.pick.poor { opacity: .5; }
[data-search][hidden], .search-section[hidden] { display: none; }
.stones { display: grid; gap: .5rem; }
.stone { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.stone { min-width: 0; }
.stone button { flex-shrink: 0; }
.item-label { flex: 1; display: flex; align-items: center; gap: .5rem; min-width: 0; }
.item-label > span { min-width: 0; }
.used-by { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chosen { display: flex; align-items: center; gap: .8rem; }

/* pokédex */
dialog:has(.dex-grid) { width: min(900px, calc(100vw - 32px)); }
.dex-stats { display: flex; gap: 1rem; color: var(--muted); margin: 0 0 .8rem; }
.dex-stats strong { color: var(--text); font-size: 1.2rem; }
dialog h3 { font-size: 1rem; margin: 1.2rem 0 .5rem; }
.dex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: .4rem; }
.dex-entry {
  position: relative; display: flex; flex-direction: column; align-items: center;
  padding: .4rem .2rem; border: 1px solid var(--line); border-radius: 10px;
  font-size: .8rem; text-align: center; min-height: 112px;
}
.dex-entry small { font-variant-numeric: tabular-nums; }
.dex-entry .sprite { width: 64px; height: 64px; }
.dex-entry.seen .sprite { filter: grayscale(.85); opacity: .7; }
.dex-entry.unseen { color: var(--muted); border-style: dashed; }
.dex-unknown { display: grid; place-items: center; width: 64px; height: 64px; font-size: 1.6rem; opacity: .4; }
.progress { display: flex; flex-wrap: wrap; justify-content: center; gap: .4rem; }
.progress .tag { white-space: nowrap; }

.dex-hof {
  position: absolute; top: 5px; left: 5px; width: 12px; height: 12px; overflow: visible;
  fill: none; stroke: var(--text); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
}
.dex-hof .cup { fill: #e8b923; }

.dex-ball {
  position: absolute; top: 5px; right: 5px; width: 12px; height: 12px; border-radius: 50%;
  border: 1.5px solid var(--text);
  background: linear-gradient(var(--accent) 0 45%, var(--text) 45% 55%, #fff 55%);
}

/* evolution scene */
dialog.evolution {
  width: min(440px, calc(100vw - 32px)); padding: 0; overflow: hidden;
  border: none; border-radius: 20px;
  background: radial-gradient(circle at 50% 40%, #3b2f7a, #120f2e 70%); color: #fff;
}
dialog.evolution::backdrop { background: rgba(5, 4, 20, .8); }
.evo-stage { position: relative; display: grid; justify-items: center; gap: 1rem; padding: 32px 20px 24px; text-align: center; }
.evo-text { margin: 0; min-height: 3em; font-size: 1.05rem; }
.evo-done { min-width: 50%; }

.evo-sprites { position: relative; width: 160px; height: 160px; }
.evo-sprites img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; image-rendering: pixelated;
}
.evo-to, .show-new .evo-from { opacity: 0; }
.show-new .evo-to { opacity: 1; }
.morphing .evo-sprites img { filter: brightness(0) invert(1) drop-shadow(0 0 12px #c4b5fd); }
.morphing .evo-sprites { animation: evo-shake .12s infinite alternate; }
@keyframes evo-shake { to { transform: translateY(-2px) scale(1.02); } }

/* the flash and the reveal */
.evo-stage::after {
  content: ""; position: absolute; inset: 0; background: #fff;
  opacity: 0; pointer-events: none;
}
.revealed::after { animation: evo-flash .9s ease-out; }
@keyframes evo-flash { 0% { opacity: 1; } 100% { opacity: 0; } }
.revealed .evo-to { animation: evo-pop .7s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes evo-pop { from { transform: scale(.6); } to { transform: scale(1); } }

.evo-rays {
  position: absolute; top: -48px; left: calc(50% - 160px); width: 320px; height: 320px;
  background: repeating-conic-gradient(rgba(255, 255, 255, .14) 0 10deg, transparent 10deg 20deg);
  border-radius: 50%; mask: radial-gradient(circle, #000 20%, transparent 70%);
  opacity: 0; pointer-events: none;
}
.morphing .evo-rays { opacity: .5; animation: evo-spin 6s linear infinite; }
.revealed .evo-rays { opacity: 1; animation: evo-spin 12s linear infinite; }
@keyframes evo-spin { to { transform: rotate(1turn); } }

/* mega evolution: rainbow aura instead of the violet glow */
dialog.evolution:has(.mega) { background: radial-gradient(circle at 50% 40%, #6b2160, #14091f 70%); }
.mega .evo-rays {
  background: repeating-conic-gradient(#ff5f6d55 0 10deg, transparent 10deg 20deg,
    #ffc37155 20deg 30deg, transparent 30deg 40deg, #7afcff55 40deg 50deg, transparent 50deg 60deg,
    #b388ff55 60deg 70deg, transparent 70deg 80deg);
}
.mega.morphing .evo-sprites img { filter: brightness(0) invert(1) drop-shadow(0 0 14px #ff9de2) drop-shadow(0 0 28px #7afcff); }
.mega.revealed .evo-to { animation: evo-pop .7s cubic-bezier(.2, 1.6, .4, 1), mega-glow 2.4s ease-in-out .7s infinite; }
@keyframes mega-glow {
  0%, 100% { filter: drop-shadow(0 0 6px #ff9de2); }
  50% { filter: drop-shadow(0 0 18px #7afcff); }
}

/* shiny scene */
dialog.evolution:has(.shiny-scene) { background: radial-gradient(circle at 50% 40%, #145a63, #06181f 70%); }
.shiny-scene .evo-rays { background: repeating-conic-gradient(#fff6a833 0 8deg, transparent 8deg 24deg); }
.shiny-scene.charging .evo-rays { opacity: .6; animation: evo-spin 5s linear infinite; }
.shiny-scene.charging .evo-from { animation: shiny-charge 3.3s ease-in forwards; }
@keyframes shiny-charge {
  from { filter: brightness(1); }
  to { filter: brightness(2.6) drop-shadow(0 0 22px #fff6a8); }
}
.sparkle {
  position: absolute; left: 50%; top: 50%; margin: -12px 0 0 -8px;
  color: #fff6a8; font-size: 22px; line-height: 1; opacity: 0; pointer-events: none;
  text-shadow: 0 0 8px #fff6a8;
}
.charging .sparkle { animation: sparkle-in 1s ease-in var(--d) infinite; }
@keyframes sparkle-in {
  from { transform: rotate(var(--a)) translateX(150px) scale(1.3); opacity: 0; }
  30% { opacity: 1; }
  to { transform: rotate(var(--a)) translateX(12px) scale(.3); opacity: 0; }
}
.shiny-scene.revealed .sparkle { animation: sparkle-out 1.4s ease-out forwards, sparkle-twinkle 1.6s ease-in-out 1.4s infinite; }
@keyframes sparkle-out {
  from { transform: rotate(var(--a)) translateX(10px) scale(.4); opacity: 1; }
  to { transform: rotate(var(--a)) translateX(95px) scale(.9); opacity: .9; }
}
@keyframes sparkle-twinkle {
  0%, 100% { transform: rotate(var(--a)) translateX(95px) scale(.9); opacity: .9; }
  50% { transform: rotate(var(--a)) translateX(88px) scale(.5); opacity: .3; }
}

@media (prefers-reduced-motion: reduce) {
  .sparkle, .shiny-scene .evo-from { animation: none !important; }
  .evo-rays, .morphing .evo-sprites, .revealed .evo-to { animation: none !important; }
}

/* journey: battle panel */
.battle-panel {
  display: grid; gap: .3rem; width: 100%; margin-bottom: 1rem; padding: .6rem .9rem;
  text-align: left; border-radius: var(--radius);
}
.battle-panel.done { text-align: center; padding: .9rem; }
.battle-panel.leader, .battle-panel.elite, .battle-panel.champion, .battle-panel.boss, .battle-panel.rival { border-color: var(--accent); }
.battle-panel.legendary { border-color: #c9a227; }
.battle-where { font-weight: 600; font-size: .9rem; }
.battle-foe { display: flex; align-items: center; gap: .6rem; }
.battle-info { flex: 1; display: grid; gap: .2rem; min-width: 0; }
.trainer-pic { image-rendering: pixelated; width: 56px; height: 56px; }
.sprite.foe { width: 64px; height: 64px; }
.sprite.foe.hit { animation: foe-hit .45s ease-in-out .3s; }
@keyframes foe-hit { 25%, 75% { transform: translateX(-4px); opacity: .4; } 50% { transform: translateX(4px); } }
.sprite.foe.appear { animation: foe-appear .5s ease-out .3s backwards; }
@keyframes foe-appear { from { transform: translateX(30px); opacity: 0; } }
.foe-queue { display: flex; flex-wrap: wrap; gap: .2rem; }
.foe-queue > span { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; }
.foe-queue .current { background: var(--bg); box-shadow: 0 0 0 1px var(--accent) inset; }
.foe-queue .fainted { opacity: .3; filter: grayscale(1); }
.sprite.tiny { width: 28px; height: 28px; }

.hp { display: block; height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.hp > span { display: block; height: 100%; border-radius: 4px; animation: hp-drop .7s ease-out .3s backwards; }
@keyframes hp-drop { from { width: var(--from); } }
.hp.high > span { background: #3fb86b; }
.hp.mid > span { background: #e8b923; }
.hp.low > span { background: #e04a3a; }

/* journey list */
.route { list-style: none; padding: 0; margin: 0; display: grid; gap: .2rem; }
.route li { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .35rem .6rem; border-radius: 8px; }
.route li.done { color: var(--muted); }
.route li.done span::before { content: "✓ "; color: var(--green); }
.route li.current { background: var(--bg); border: 1px solid var(--accent); font-weight: 600; }
.route li.current span::before { content: "▶ "; color: var(--accent); }
.route li.next { color: var(--muted); opacity: .6; }

/* badges & trainer card */
.badge-icon { image-rendering: pixelated; width: 40px; height: 40px; vertical-align: middle; }
.badge-icon.small { width: 20px; height: 20px; }
.badge-icon.big { width: 80px; height: 80px; }
.badge-icon.locked { filter: grayscale(1) brightness(.7); opacity: .25; }
.trainer-card { display: grid; gap: .6rem; }
.tc-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .6rem .8rem; border-radius: var(--radius); background: var(--bg); }
.tc-head h2 { margin: 0; }
.trainer-pic.player { width: 84px; height: 84px; }
.trainer-card dl { display: grid; grid-template-columns: auto 1fr; gap: .3rem 1rem; margin: 0; }
.trainer-card dt { color: var(--muted); }
.trainer-card dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.badge-regions { display: grid; gap: .4rem; }
.badge-row {
  display: flex; justify-content: space-between; align-items: center; gap: .6rem;
  padding: .4rem .6rem; border: 1px solid var(--line); border-radius: 10px;
}
.badge-icons { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .1rem; }
.badge-icons .badge-icon { width: 28px; height: 28px; }
.route-done summary { cursor: pointer; list-style: none; }
.route-done summary::-webkit-details-marker { display: none; }
.route-done summary h3 { display: inline-block; }
.route-next { color: var(--muted); }
dialog.evolution:has(.region-scene) { background: radial-gradient(circle at 50% 40%, #1f6b4a, #06180f 70%); }

/* badge and champion scene */
dialog.evolution:has(.badge-scene) { background: radial-gradient(circle at 50% 40%, #7a5a14, #1f1405 70%); }
.badge-scene .evo-rays { background: repeating-conic-gradient(#ffe7a033 0 8deg, transparent 8deg 20deg); }
.badge-scene.arrive .evo-rays { opacity: .6; animation: evo-spin 8s linear infinite; }
.badge-stage { position: relative; width: 200px; height: 160px; display: grid; place-items: center; }
.badge-stage .leader { position: absolute; width: 112px; height: 112px; opacity: .9; transition: opacity .8s, transform .8s; }
.badge-scene.arrive .leader { opacity: .25; transform: scale(.9); }
.badge-drop {
  position: relative; width: 96px; height: 96px; image-rendering: pixelated;
  opacity: 0; transform: translateY(-140px) rotate(-540deg) scale(.4);
}
.badge-scene.arrive .badge-drop { animation: badge-fall 1.4s cubic-bezier(.2, .9, .3, 1.15) forwards; }
@keyframes badge-fall { to { opacity: 1; transform: none; } }
.badge-scene.revealed .badge-drop { animation: badge-shine 2s ease-in-out infinite; opacity: 1; transform: none; }
@keyframes badge-shine {
  0%, 100% { filter: drop-shadow(0 0 6px #ffe7a0); transform: scale(1); }
  50% { filter: drop-shadow(0 0 22px #fff6c8) brightness(1.25); transform: scale(1.08); }
}
.trophy { font-size: 80px; line-height: 96px; text-align: center; }
dialog.evolution:has(.champion-scene) { background: radial-gradient(circle at 50% 40%, #8a1f2b, #1d0508 70%); }

@media (prefers-reduced-motion: reduce) {
  .sprite.foe, .hp > span, .badge-drop, .badge-scene .evo-rays { animation: none !important; }
  .badge-drop { opacity: 1; transform: none; }
}

/* toasts */
#toasts {
  position: fixed; bottom: calc(16px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  display: grid; gap: .4rem; z-index: 10; width: min(420px, calc(100vw - 32px));
}
/* Like the cards, with a colored edge; a message's "\n" starts a new line. */
.toast {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-left: 4px solid var(--exp); border-radius: var(--radius);
  padding: .6rem .9rem; font-size: .92rem; line-height: 1.4; white-space: pre-line;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .14);
  animation: pop .2s ease-out;
}
.toast.error { border-left-color: var(--accent); }
.toast p { margin: 0; }
.toast p + p { margin-top: .3rem; }
.toast.lead p:first-child:not(:only-child) { font-weight: 600; }

/* Achievements: gold, a glow that breathes, a sheen running across and sparkles around the icon. */
.toast.achievement {
  --gold: #e8b923;
  position: relative; overflow: hidden; cursor: pointer;
  display: flex; align-items: center; gap: .9rem; white-space: normal;
  border: 2px solid var(--gold); padding: .7rem 1rem;
  background: linear-gradient(135deg, var(--surface) 55%, color-mix(in srgb, var(--gold) 22%, var(--surface)));
  animation: pop .3s ease-out, ach-glow 1.6s ease-in-out infinite alternate;
  transition: opacity .4s;
}
.toast.achievement.leaving { opacity: 0; }
.toast.achievement::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(110deg, transparent 35%, rgba(255, 255, 255, .5) 50%, transparent 65%);
  transform: translateX(-100%); animation: ach-sheen 3s ease-in-out infinite;
}
@keyframes ach-sheen { 50%, 100% { transform: translateX(100%); } }
@keyframes ach-glow { to { box-shadow: 0 6px 18px rgba(0, 0, 0, .14), 0 0 20px 2px rgba(232, 185, 35, .55); } }
.ach-icon { position: relative; flex: none; width: 48px; height: 48px; display: grid; place-items: center; }
.ach-emoji { font-size: 2.1rem; line-height: 1; }
.ach-icon .sprite, .ach-icon .item-icon, .ach-icon .ball { width: 100%; height: 100%; }
.ach-sparkle {
  position: absolute; color: #e8b923; font-size: .85rem; pointer-events: none;
  animation: ach-twinkle 1.8s ease-in-out infinite backwards;
}
@keyframes ach-twinkle { 0%, 100% { opacity: 0; transform: scale(.3); } 50% { opacity: 1; transform: scale(1.15) rotate(45deg); } }
.ach-text { display: grid; gap: .05rem; }
.ach-text small { color: #b8860b; font-weight: 700; font-size: .68rem; letter-spacing: .06em; text-transform: uppercase; }
.ach-text strong { font-size: 1.02rem; }
.ach-text span { color: var(--muted); font-size: .85rem; }
@media (prefers-reduced-motion: reduce) {
  .toast.achievement, .toast.achievement::after, .ach-sparkle { animation: none; }
  .ach-sparkle { display: none; }
}

/* The achievements on the trainer card. */
/* An easter egg. */
.dex-entry.glitch { animation: glitch 2.4s steps(1) infinite; }
@keyframes glitch {
  0%, 86%, 100% { transform: none; filter: none; }
  88% { transform: translate(2px, -1px) skewX(8deg); filter: invert(1); }
  92% { transform: translate(-3px, 1px); filter: hue-rotate(90deg) saturate(4); }
  96% { transform: translate(1px, 2px) skewX(-6deg); }
}
@media (prefers-reduced-motion: reduce) { .dex-entry.glitch { animation: none; } }

.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: .5rem; }
.ach { display: grid; justify-items: center; align-content: start; gap: .25rem; padding: .55rem .3rem; text-align: center; }
.ach small { font-size: .72rem; line-height: 1.2; }
.ach .ach-icon { width: 38px; height: 38px; }
.ach .ach-emoji { font-size: 1.7rem; }
.ach.done { border-color: #e8b923; }
.ach.locked .ach-icon { filter: grayscale(1); opacity: .35; }
.ach.locked small { color: var(--muted); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 600px) {
  /* home: hatch spot as one slim row, the whole team of 6 in view without scrolling */
  main { padding-top: 12px; padding-bottom: 12px; }
  .top { padding: .6rem .9rem; }
  .top { margin-bottom: .8rem; }
  .icon-button { padding: .3rem; }
  .field { grid-template-columns: 1fr; gap: .8rem; }
  h2 { font-size: .95rem; margin-bottom: .4rem; }
  .hatch .card { flex-direction: row; justify-content: flex-start; gap: .8rem; min-height: 0; padding: .5rem .9rem; }
  .hatch .card.add { justify-content: center; min-height: 64px; }
  .hatch .egg { width: 46px; height: 58px; margin: 0; }
  .hatch .egg .inside { width: 38px; height: 38px; }
  .team { grid-template-columns: repeat(3, 1fr); gap: .5rem; }
  .card { min-height: 128px; padding: .5rem .3rem; }
  .card .sprite { width: 56px; height: 56px; }
  .nick { font-size: .9rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .habit { font-size: .75rem; }
  .lv { font-size: .72rem; }
  .bubble { min-width: 1.3rem; height: 1.3rem; font-size: .72rem; }
  .bubble.red { top: -5px; right: -5px; }
  .bubble.green { bottom: -5px; left: -5px; }
  .bubble.dot { min-width: 0; width: 1.05rem; height: 1.05rem; top: -5px; right: -5px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); }
  .dex-grid { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); }
  .battle-panel { margin-bottom: .8rem; padding: .5rem .7rem; }
  .trainer-pic { width: 44px; height: 44px; }
  .sprite.foe { width: 52px; height: 52px; }

  /* dialogs become bottom sheets */
  #dialog {
    width: 100%; max-width: 100%; max-height: 88dvh; margin: auto 0 0;
    border-radius: 20px 20px 0 0; border-width: 1px 0 0;
    padding: 12px max(16px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
  #dialog::before {
    content: ""; display: block; width: 40px; height: 4px; margin: 0 auto 10px;
    border-radius: 2px; background: var(--line);
  }
  #dialog[open] { animation: sheet-up .25s ease-out; }

  #debug-bar { font-size: .8rem; gap: .3rem; padding: .4rem 12px; }
  #debug-bar button { padding: .2rem .5rem; }
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: .5; } }
@media (prefers-reduced-motion: reduce) {
  #dialog[open] { animation: none; }
}

/* calendar: a month of days with a dot per completion, each week's ball on the right */
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin: 0 0 .6rem; }
.cal-nav button { padding: .3rem .8rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)) 2rem; gap: 4px; }
.cal-head { text-align: center; font-size: .75rem; color: var(--muted); }
.cal-day {
  aspect-ratio: 1; min-width: 0; padding: 3px 2px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; align-items: center; gap: 2px; overflow: hidden;
}
.cal-day small { font-size: .72rem; line-height: 1; }
.cal-day.outside { border: none; background: none; }
.cal-day.future { opacity: .4; }
.cal-day.today { border-color: var(--accent); }
.cal-day.selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.dots { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; }
.dot { width: 6px; height: 6px; border-radius: 50%; }
/* a hit a bit stronger than its button, so it stays a filled dot and doesn't read as a minimum's ring */
.dot.grade-hit { background: color-mix(in srgb, var(--accent) 55%, #fff); }
.dot.grade-super { background: var(--grade-super); }
.dot.grade-critical { background: var(--grade-critical); }
.dot.grade-minimum { box-shadow: inset 0 0 0 1px var(--muted); }
.dot.skipped { background: var(--line); }
.cal-ball { display: grid; place-items: center; }
.ball { width: 28px; height: 28px; image-rendering: pixelated; }
.ball.provisional { opacity: .4; }
.cal-legend { display: flex; flex-wrap: wrap; gap: .3rem .8rem; margin-top: .8rem; font-size: .8rem; color: var(--muted); }
.cal-legend span { display: flex; align-items: center; gap: .2rem; }
.cal-legend .ball { width: 22px; height: 22px; }
.cal-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .3rem; }
.cal-list li { display: flex; align-items: center; gap: .5rem; }
.cal-list .habit-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-list .tag { flex-shrink: 0; }
.cal-list .tag.grade-hit { background: var(--grade-hit); color: #2a2522; }
.cal-list .tag.grade-super { background: var(--grade-super); color: #fff; }
.cal-list .tag.grade-critical { background: var(--grade-critical); color: #fff; }
