:root {
  --bg: #fff8ef;
  --paper: #ffffff;
  --ink: #3b2f45;
  --ink-soft: #7a6c86;
  --line: #3b2f45;
  --pink: #ff8fb1;
  --pink-deep: #e5739d;
  --mint: #8fd3b8;
  --sky: #8fd3e8;
  --sun: #ffd23f;
  --lilac: #b9a7ff;
  --peach: #ffc9a8;
  --shadow: #e8d6c4;
  --px: 4px;
  --font: "Press Start 2P", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(circle at 1px 1px, #f3e3cf 1px, transparent 1.5px) 0 0 / 14px 14px,
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 10px;
  line-height: 1.7;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; color: inherit; }
.hidden { display: none !important; }

/* pixel border helper */
.panel, #dialog, #hud, .px-btn, #modal {
  background: var(--paper);
  border: 3px solid var(--line);
  box-shadow: 0 4px 0 0 var(--shadow), 4px 4px 0 0 var(--shadow);
  border-radius: 2px;
}

#app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 12px 24px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* ---------- HUD ---------- */
#hud {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
  padding: 8px 10px; margin-bottom: 12px;
  background: linear-gradient(#fff, #fff6f9);
}
.hud-block { display: flex; flex-direction: column; min-width: 0; }
.hud-block.wide { flex: 1 1 140px; }
.hud-label { font-size: 7px; color: var(--ink-soft); letter-spacing: 1px; }
#hud-date, #hud-age, #hud-money, #hud-status { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#hud-money { color: #2f8f5b; }
.hud-buttons { display: flex; gap: 6px; margin-left: auto; }
.icon-btn {
  width: 34px; height: 34px; font-size: 16px; line-height: 1; cursor: pointer;
  background: #fff; border: 3px solid var(--line); box-shadow: 0 3px 0 var(--shadow);
  font-family: system-ui, sans-serif; padding: 0;
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }

/* ---------- layout ---------- */
#main { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 900px) {
  #main { grid-template-columns: minmax(0, 1.65fr) minmax(300px, 1fr); align-items: start; }
  #side { position: sticky; top: 10px; }
}

#stage { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
#screen-wrap { position: relative; border: 3px solid var(--line); box-shadow: 0 4px 0 var(--shadow), 4px 4px 0 var(--shadow); background: #fff; line-height: 0; }
#screen {
  width: 100%; height: auto; aspect-ratio: 16 / 9; display: block;
  image-rendering: pixelated; image-rendering: crisp-edges;
}
#toast {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  background: var(--sun); border: 3px solid var(--line); padding: 6px 10px; font-size: 9px; line-height: 1.5;
  white-space: nowrap; animation: pop .25s steps(3);
}
@keyframes pop { from { transform: translate(-50%, -8px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ---------- dialog ---------- */
#dialog { position: relative; padding: 18px 14px 14px; min-height: 108px; cursor: pointer; user-select: none; }
#dlg-name {
  position: absolute; top: -13px; left: 10px; padding: 3px 8px; font-size: 9px;
  background: var(--pink); color: #fff; border: 3px solid var(--line);
}
#dlg-text { font-size: 11px; line-height: 1.9; white-space: pre-wrap; word-break: break-word; }
#dlg-next { position: absolute; right: 10px; bottom: 6px; font-size: 10px; animation: bob .8s steps(2) infinite; color: var(--pink-deep); }
@keyframes bob { 50% { transform: translateY(3px); } }
#dlg-choices { display: grid; gap: 8px; margin-top: 10px; }
#dlg-choices:empty { display: none; }
.choice {
  text-align: left; padding: 10px 12px; font-size: 10px; line-height: 1.6; cursor: pointer;
  background: #fff7fa; border: 3px solid var(--line); box-shadow: 0 3px 0 var(--shadow);
}
.choice:hover, .choice:focus-visible { background: #ffe3ee; outline: none; }
.choice:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }
.choice::before { content: "▶ "; color: var(--pink-deep); }
.choice[disabled] { opacity: .45; cursor: not-allowed; }

/* ---------- side ---------- */
#side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
#best { padding: 10px; background: linear-gradient(#fffbea, #fff); }
.best-row { display: flex; justify-content: space-between; gap: 8px; font-size: 9px; margin-bottom: 6px; }
#best-title { color: #b8860b; }
.bar { height: 12px; border: 2px solid var(--line); background: #f4eee8; position: relative; overflow: hidden; }
.fill { height: 100%; width: 0; background: var(--sun); transition: width .4s steps(8);
  background-image: repeating-linear-gradient(90deg, transparent 0 6px, rgba(255,255,255,.35) 6px 8px); }

#stats { padding: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.stat { min-width: 0; }
.stat-top { display: flex; justify-content: space-between; font-size: 8px; margin-bottom: 3px; }
.stat-top span:last-child { color: var(--ink-soft); }

#actions { padding: 10px; }
#actions h3 { margin: 0 0 8px; font-size: 9px; font-weight: normal; color: var(--ink-soft); }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (min-width: 560px) and (max-width: 899px) { .action-grid { grid-template-columns: repeat(3, 1fr); } }
.act {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left;
  padding: 8px; min-height: 64px; cursor: pointer; font-size: 9px; line-height: 1.5;
  background: #fff; border: 3px solid var(--line); box-shadow: 0 3px 0 var(--shadow);
}
.act .ico { font-family: system-ui, "Apple Color Emoji", "Segoe UI Emoji", sans-serif; font-size: 18px; line-height: 1; }
.act small { font-size: 7px; color: var(--ink-soft); line-height: 1.5; }
.act:hover:not([disabled]) { background: #f0fbff; }
.act:active:not([disabled]) { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }
.act[disabled] { opacity: .5; cursor: default; }
.act.hot { background: #fff4d6; }

/* ---------- modal ---------- */
#overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(255, 244, 230, .82); overflow-y: auto;
  padding: calc(14px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) calc(14px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  backdrop-filter: blur(2px);
}
#modal { width: min(640px, 100%); max-height: calc(100vh - 28px); overflow-y: auto; padding: 18px 16px; margin: auto; }
#modal h2 { font-size: 13px; margin: 0 0 12px; color: var(--pink-deep); line-height: 1.6; }
#modal h3 { font-size: 10px; margin: 16px 0 8px; color: var(--ink); }
#modal p { font-size: 9px; line-height: 1.9; margin: 0 0 10px; }
#modal label { display: block; font-size: 8px; margin: 10px 0 4px; color: var(--ink-soft); }
#modal textarea, #modal input[type=text], #modal input[type=password] {
  width: 100%; font-family: inherit; font-size: 10px; line-height: 1.8; padding: 8px; color: var(--ink);
  background: #fffaf3; border: 3px solid var(--line); border-radius: 0; resize: vertical;
}
#modal textarea:focus, #modal input:focus { outline: none; background: #fff; box-shadow: 0 0 0 3px var(--pink); }
.goal-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.goal-row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--pink-deep); flex: none; }
.modal-btns { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; justify-content: flex-end; }
.px-btn { padding: 10px 14px; font-size: 10px; cursor: pointer; background: var(--pink); color: #fff; }
.px-btn.alt { background: #fff; color: var(--ink); }
.px-btn:active { transform: translateY(2px); }
.card { border: 3px dashed var(--line); padding: 10px; margin-bottom: 10px; background: #fffdf3; }
.card b { display: block; font-size: 9px; margin-bottom: 6px; color: #2f8f5b; font-weight: normal; }
.card span { font-size: 8px; line-height: 1.9; display: block; }
.card.locked { opacity: .45; background: #f6f2ee; }
.letter { background: #fff7fa; border: 3px solid var(--pink); padding: 14px; font-size: 9px; line-height: 2; white-space: pre-wrap; }
.ending-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; font-size: 8px; }
.ending-stats div { border-bottom: 2px dotted var(--shadow); padding: 4px 0; }
ul.pix { list-style: none; padding: 0; margin: 0; font-size: 8px; line-height: 2; }
ul.pix li::before { content: "♥ "; color: var(--pink-deep); }

/* ---------- title ---------- */
.title-big { font-size: 18px !important; text-align: center; line-height: 1.5 !important; color: var(--pink-deep) !important;
  text-shadow: 3px 3px 0 #ffe08a; }
.center { text-align: center; }

@media (max-width: 520px) {
  body { font-size: 9px; }
  #app { padding-top: 8px; }
  #hud { gap: 4px 10px; padding: 6px 8px; }
  .hud-buttons { width: 100%; justify-content: flex-end; margin-top: 2px; }
  #dlg-text { font-size: 10px; }
  .title-big { font-size: 14px !important; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* on phones/tablets, put the action menu right under the dialog */
@media (max-width: 899px) {
  #actions { order: -1; }
}

/* ---------- life recap ---------- */
.recap-stage { position: relative; border: 3px solid var(--line); background: #fff; line-height: 0; box-shadow: 0 4px 0 var(--shadow); }
.recap-stage img { width: 100%; max-width: 100%; height: auto; aspect-ratio: 16 / 9; display: block; image-rendering: pixelated; image-rendering: crisp-edges; }
.recap-when { position: absolute; left: 8px; top: 8px; line-height: 1.4; font-size: 8px; padding: 4px 6px; background: var(--sun); border: 2px solid var(--line); }
#modal p.recap-cap { font-size: 10px; text-align: center; min-height: 3.6em; margin: 12px 0 6px; text-wrap: balance; }
.recap-dots { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.recap-dots i { width: 8px; height: 8px; background: var(--shadow); display: block; }
.recap-dots i.on { background: var(--pink-deep); }
.recap-ctrl { justify-content: center; margin-top: 10px; }
.recap-card { width: 100%; max-width: 100%; height: auto; display: block; border: 3px solid var(--line); margin: 6px 0 10px; }
#r-share textarea { margin-top: 8px; }

/* ---------- time capsule ---------- */
#modal input[type=file] { width: 100%; font-family: inherit; font-size: 9px; padding: 8px; border: 3px dashed var(--line); background: #fffaf3; }
#modal input[type=date] { width: 100%; font-family: inherit; font-size: 10px; padding: 8px; border: 3px solid var(--line); background: #fffaf3; color: var(--ink); }
.cap-thumbs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 8px; }
.cap-thumbs img { width: 100%; max-width: 100%; aspect-ratio: 1; object-fit: cover; border: 2px solid var(--line); }
#modal p.cap-status { min-height: 1.6em; margin: 10px 0 0; color: #b0476e; }

/* ---------- background music ---------- */
#radio { padding: 10px; }
.radio-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 9px; margin-bottom: 8px; }
.radio-btn { font-family: inherit; font-size: 8px; padding: 6px 8px; cursor: pointer; background: #fff7fa; border: 3px solid var(--line); box-shadow: 0 2px 0 var(--shadow); }
.radio-btn:active { transform: translateY(2px); box-shadow: none; }
#radio-player { position: relative; width: 100%; aspect-ratio: 16 / 9; max-width: 100%; border: 3px solid var(--line); background: #f4eee8; }
#radio-player iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
#radio-player:has(.radio-note) { aspect-ratio: auto; }
.radio-note { margin: 0; padding: 10px; font-size: 8px; line-height: 1.9; }
.radio-note a { color: var(--pink-deep); }

/* ---------- Ko-fi ---------- */
a.px-btn { display: inline-block; text-decoration: none; line-height: 1.6; }
.kofi-btn { background: #29abe0; color: #fff; }
.kofi-btn:hover, .kofi-btn:focus-visible { background: #1f93c4; outline: none; }
.kofi-box { margin-top: 16px; padding: 12px; border: 3px dashed var(--line); background: #f0fbff; text-align: center; }
#modal .kofi-box p { font-size: 9px; margin: 0 0 10px; }
