:root {
  --bg: #f4ecdb;
  --card: #fffaf0;
  --ink: #2b2220;
  --muted: #7a6a5c;
  --line: #d9cbb1;
  --accent: #3f8f2f;
  --accent-ink: #ffffff;
  --warn: #b0562e;
  --pixel: 'Pixelify Sans', ui-monospace, monospace;
  /* Numbers only ever render in this: the pixel font's digits are too easy
     to misread, and every number here is one a 7-year-old acts on.
     It is only the family. A size cannot live in here: a custom property
     containing var() is resolved where it is defined, on :root, so an
     element setting its own size afterwards changes nothing, and every
     number came out at the fallback. */
  --numerals: system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

/* An explicit `display` in a rule below beats the browser's own [hidden]
   styling, so anything flex or grid would stay on screen when hidden. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 system-ui, -apple-system, sans-serif;
}

.app {
  max-width: 768px;
  margin: 0 auto;
  /* Keep clear of the notch and home bar when installed on a phone. */
  padding:
    calc(24px + env(safe-area-inset-top))
    calc(16px + env(safe-area-inset-right))
    calc(40px + env(safe-area-inset-bottom))
    calc(16px + env(safe-area-inset-left));
}

.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

h1, h2, h3 { font-family: var(--pixel); margin: 0; }
h1 { font-size: 28px; }
h2 { font-size: 18px; overflow-wrap: anywhere; }
h3 { font-size: 17px; }
.today { margin: 0; color: var(--muted); }
.top-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ---- The room ---- */

#scene {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  border: 3px solid var(--ink);
  border-radius: 4px;
  /* It is pokeable. */
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Level-ups and evolutions, announced over the room for a few seconds. */
.cheer {
  margin: 0;
  height: 0;
  overflow: hidden;
  text-align: center;
  font-family: var(--pixel);
  font-size: 17px;
  color: var(--accent);
  opacity: 0;
  transition: opacity 180ms ease, height 180ms ease;
}
.cheer.shown { height: 26px; opacity: 1; }

/* ---- Status strip ---- */

.status {
  margin-top: 10px;
  padding: 12px 14px;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 6px;
}
.status-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.level {
  font: 600 15px/1.2 var(--numerals);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.who { min-width: 0; }
/* Species and form, under the name he gave it. */
.kind { margin: 0; color: var(--muted); font-size: 13px; }

.xp {
  margin-top: 8px;
  height: 14px;
  background: #ece2cd;
  border: 2px solid var(--ink);
  border-radius: 3px;
  overflow: hidden;
}
/* Red when empty, green as it fills. The width and color are set in code.
   The minimum keeps a sliver of red visible at zero, so an empty bar still
   reads as empty rather than as missing. */
.xp-fill {
  height: 100%;
  width: 0;
  min-width: 5px;
  transition: width 240ms ease, background-color 240ms ease;
}

.status-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
}
.xp-label {
  font: 600 14px/1.2 var(--numerals);
  font-variant-numeric: tabular-nums;
}

.pips { display: inline-flex; gap: 4px; }
.pip {
  width: 12px;
  height: 12px;
  border: 2px solid var(--ink);
  border-radius: 2px;
  background: #ece2cd;
}
.pip.full { background: var(--warn); }

.manage-monster { display: flex; gap: 14px; margin: 6px 0 0; }

.rename-row {
  display: flex;
  gap: 6px;
  margin: 8px 0;
}
.rename-row input { flex: 1; min-width: 0; }
.rename-row button { white-space: nowrap; padding: 6px 10px; }

.feed { margin-top: 10px; width: 100%; }
.feed:disabled {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
  cursor: default;
  filter: none;
}

/* ---- Stats ---- */

.stats-panel {
  margin-top: 10px;
  padding: 12px 14px;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 6px;
}
.stat-list {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px 10px;
  margin: 8px 0 0;
}
.stat-list dt { color: var(--muted); font-size: 13px; }
.stat-list dd {
  margin: 0;
  font: 600 20px/1.2 var(--numerals);
  font-variant-numeric: tabular-nums;
}

/* ---- Habit cards ---- */

.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.card {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.card p { margin: 0; }
.meta { color: var(--muted); font-size: 13px; }
.trains {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}
.trains span { flex: none; }
.trains select { flex: 1; min-width: 0; font-size: 14px; padding: 4px 6px; }

.card.empty { border-style: dashed; justify-content: center; }
.hint { color: var(--muted); text-align: center; }


/* ---- The picker ---- */

.picker-title { font-size: 24px; }
.picker-lede { margin: 4px 0 16px; color: var(--muted); }
.picks {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.pick {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.pick.current { border-color: var(--accent); }
.pick-frame {
  background: #ece2cd;
  border-radius: 8px;
  display: grid;
  place-items: center;
  /* Without an explicit width this shrinks to the canvas's natural 64px
     instead of filling the card. */
  width: 100%;
  aspect-ratio: 1;
  margin-bottom: 4px;
}
.pick-art {
  image-rendering: pixelated;
  width: 100%;
  height: auto;
}
.pick .element { margin: 0; color: var(--muted); font-size: 13px; }
.pick .blurb { margin: 0 0 8px; font-size: 14px; text-align: left; }
.pick button { margin-top: auto; }
.picker-note { margin-top: 18px; color: var(--muted); font-size: 14px; }

/* ---- Controls ---- */

button, .file {
  font: inherit;
  font-family: var(--pixel);
  font-size: 15px;
  cursor: pointer;
  border: 2px solid var(--ink);
  border-radius: 4px;
  padding: 6px 10px;
  background: var(--accent);
  color: var(--accent-ink);
}
button:hover { filter: brightness(1.08); }

button.ghost, .ghost {
  background: transparent;
  color: var(--ink);
}
button.small { padding: 2px 8px; font-size: 13px; }

button.link {
  border: 0;
  padding: 6px 0; /* bigger tap target on phones */
  background: none;
  color: var(--muted);
  font: 12px system-ui, sans-serif;
  text-decoration: underline;
}

input, select {
  font: inherit;
  width: 100%;
  min-width: 0;
  padding: 6px 8px;
  border: 2px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
}

.card > button, .log, .done, .add { margin-top: 8px; }
.log { display: flex; gap: 6px; }
.log button { white-space: nowrap; }
.add { display: flex; flex-direction: column; gap: 6px; }
.done {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.manage { display: flex; gap: 12px; margin-top: auto; padding-top: 8px; }

/* ---- Footer ---- */

.bottom { margin-top: 24px; color: var(--muted); font-size: 13px; }
.backup { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.file input { display: none; }
.stale { color: var(--warn); }
.art-note { margin: 10px 0 0; color: var(--warn); }
.links { margin: 12px 0 0; }
.links a { color: var(--muted); }

@media (max-width: 600px) {
  .cards, .picks { grid-template-columns: 1fr; }
  .pick-frame { max-width: 240px; margin-inline: auto; }
  .stat-list { grid-template-columns: repeat(2, 1fr); }
}

/* ---- The game ---- */

.play-row { margin-top: 10px; }
.play { width: 100%; font-size: 17px; padding: 8px 10px; }
.play.locked {
  background: #e7dcc6;
  color: var(--muted);
  border-color: var(--line);
}
.play.shake { animation: shake 380ms ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
@media (prefers-reduced-motion: reduce) {
  .play.shake { animation: none; }
}
.tomorrow { margin: 6px 0 0; font-size: 13px; color: var(--muted); text-align: center; }
.tomorrow.ready { color: var(--accent); font-weight: 600; }

.arena-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  max-width: 460px;
  margin: 0 auto 8px;
}
.arena-score {
  font: 600 22px/1.2 var(--numerals);
  font-variant-numeric: tabular-nums;
}
.arena-board {
  position: relative;
  max-width: 460px;
  margin: 0 auto;
}
#arena-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  image-rendering: pixelated;
  border: 3px solid var(--ink);
  border-radius: 4px;
  background: #f4e7cd;
  touch-action: none;
}
.arena-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(43, 34, 32, 0.45);
  border-radius: 4px;
}
.card-overlay {
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 16px 18px;
  margin: 12px;
  max-width: 290px;
  text-align: center;
}
.card-overlay.tap { cursor: pointer; }
.card-overlay h3 { font-size: 22px; margin-bottom: 8px; }
.card-overlay p { margin: 6px 0; }
.big-score {
  font: 600 46px/1.2 var(--numerals);
  font-variant-numeric: tabular-nums;
}
.muted { color: var(--muted); }
.overlay-buttons { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.arena-banner {
  position: absolute;
  inset: 10px 0 auto;
  margin: 0;
  text-align: center;
  font-family: var(--pixel);
  font-size: 20px;
  color: var(--ink);
  text-shadow: 0 1px 0 #fffaf0, 0 -1px 0 #fffaf0, 1px 0 0 #fffaf0, -1px 0 0 #fffaf0;
  opacity: 0;
  transition: opacity 200ms ease;
  pointer-events: none;
}
.arena-banner.shown { opacity: 1; }

/* A cross of four big buttons. Big enough to hit without looking. */
.pad {
  display: grid;
  grid-template-columns: repeat(3, 68px);
  grid-template-rows: repeat(3, 58px);
  gap: 6px;
  justify-content: center;
  margin-top: 14px;
}
.pad button {
  font-size: 22px;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.pad-up { grid-column: 2; grid-row: 1; }
.pad-left { grid-column: 1; grid-row: 2; }
.pad-right { grid-column: 3; grid-row: 2; }
.pad-down { grid-column: 2; grid-row: 3; }
.card-overlay .why { font-weight: 600; margin: 0 0 6px; }
.card-overlay .win-time { font-family: var(--numerals); font-size: 20px; margin: 0 0 6px; }
.build { margin: 8px 0 0; font-size: 11px; color: var(--muted); opacity: 0.7; }
.card-overlay.win { border-color: var(--accent); box-shadow: 0 0 0 3px #f6d98a; }
.card-overlay.win h3 { color: var(--accent); }

/* ---- One-off welcome card (js/greeting.js) ---- */
.greeting {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(43, 34, 32, 0.55);
}
.greeting-card {
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 10px;
  box-shadow: 0 0 0 3px #f6d98a;
  padding: 16px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.greeting-art {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  margin-bottom: 12px;
}
.greeting-stand-in { font-size: 40px; margin: 4px 0 8px; letter-spacing: 4px; }
.greeting-card h2 { font-family: var(--pixel); font-size: 26px; margin: 0 0 6px; }
.greeting-card p { margin: 0 0 14px; }
.greeting-card button { min-width: 140px; }
