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

:root {
  --white: #ffffff;
  --frame: #ffffff;          /* changed by the FRAMES shop items */
  --yellow: #ffff00;
  --red: #ff0000;
  --orange: #ff7f27;
  --bar-bg: #c00000;
  --xp: #00a2e8;
  --grey: #777777;
}

html, body {
  margin: 0;
  background: #000;
  color: var(--white);
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: 12px;
  line-height: 1.8;
  image-rendering: pixelated;
}

body {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 16px;
}

#game {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#bg {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  pointer-events: none;
}

/* ---------- THE CLASSIC BORDERED BOX ---------- */
.box {
  border: 4px solid var(--frame);
  padding: 16px;
  background: #000;
}

/* ---------- STATUS BAR ---------- */
#status {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 16px;
  background: #000;
  border: 4px solid var(--frame);
  padding: 12px 16px;
}

#soul { width: 32px; height: 28px; image-rendering: pixelated; }

.who { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 140px; }
.whorow { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.linkbtn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--white);
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 1px;
  cursor: pointer;
}
.linkbtn:hover { color: var(--yellow); }
.small-link { font-size: 9px; margin-top: 12px; text-align: left; }
.danger { color: #c05050; }
.danger:hover { color: var(--red); }

#name-input { width: 13ch; flex: none; padding: 4px 6px; border-width: 3px; font-size: 12px; }

.coin { color: var(--yellow); }
.coin::before {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 8px;
  vertical-align: -2px;
  image-rendering: pixelated;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 7' shape-rendering='crispEdges'%3E%3Cg fill='%23ffd700'%3E%3Crect x='3' y='0' width='1' height='2'/%3E%3Crect x='2' y='2' width='3' height='1'/%3E%3Crect x='0' y='3' width='7' height='1'/%3E%3Crect x='1' y='4' width='5' height='1'/%3E%3Crect x='2' y='5' width='1' height='1'/%3E%3Crect x='4' y='5' width='1' height='1'/%3E%3Crect x='1' y='6' width='1' height='1'/%3E%3Crect x='5' y='6' width='1' height='1'/%3E%3C/g%3E%3C/svg%3E") no-repeat center / contain;
}

/* PET MONSTER */
.petbtn { background: none; border: 0; padding: 0; cursor: pointer; line-height: 0; }
.petbtn:hover, .petbtn:focus-visible { border: 0; }
#pet { width: 60px; height: 60px; image-rendering: pixelated; animation: bob 1s steps(2) infinite; }
#pet.sad { animation-duration: 2.4s; filter: saturate(0.4) brightness(0.8); }
#pet.hop { animation: hop 0.3s steps(3); }

@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes hop { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-16px); } }

.bars { width: 100%; display: flex; flex-direction: column; gap: 8px; }
.barrow { display: flex; align-items: center; gap: 12px; }
.label { width: 28px; font-size: 10px; }

.bar { flex: 1; height: 20px; background: var(--bar-bg); border: 0; }
.fill { height: 100%; width: 100%; transition: width 0.3s steps(6); }
.fill.hp { background: var(--yellow); }
.fill.xp { background: var(--xp); }

#hptext, #xptext { font-size: 10px; min-width: 84px; text-align: right; }

/* ---------- STREAK BAR ---------- */
.streak-head { display: flex; justify-content: space-between; margin-bottom: 12px; }
#streak-count { color: var(--orange); }

#streak-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.sday { text-align: center; }
.sq { height: 24px; border: 4px solid #555; background: #000; }
.sday.on .sq   { background: var(--yellow); border-color: var(--yellow); }
.sday.ice .sq  { background: var(--xp); border-color: var(--xp); }
.sday.today .sq { border-color: var(--white); }
.sday.today.on .sq { border-color: var(--orange); }
.sl { font-size: 8px; margin-top: 6px; color: var(--grey); }
.sday.today .sl { color: var(--white); }

/* ---------- TABS ---------- */
#tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tab { font-size: 9px; padding: 10px 2px; }
.tab.active { color: var(--yellow); border-color: var(--yellow); }

/* ---------- HABITS ---------- */
#habits { list-style: none; margin: 0 0 16px; padding: 0; }

#habits li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 32px;
  position: relative;
  cursor: pointer;
}

#habits li:hover::before,
#habits li:focus-within::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 50%;
  width: 16px;
  height: 14px;
  margin-top: -7px;
  image-rendering: pixelated;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 7' shape-rendering='crispEdges'%3E%3Cg fill='%23ff0000'%3E%3Crect x='1' y='0' width='2' height='1'/%3E%3Crect x='5' y='0' width='2' height='1'/%3E%3Crect x='0' y='1' width='8' height='3'/%3E%3Crect x='1' y='4' width='6' height='1'/%3E%3Crect x='2' y='5' width='4' height='1'/%3E%3Crect x='3' y='6' width='2' height='1'/%3E%3C/g%3E%3C/svg%3E") no-repeat center / contain;
}

#habits li.done .habit-name { color: var(--yellow); }

.check {
  width: 24px; height: 24px;
  border: 4px solid var(--white);
  background: #000;
  color: var(--yellow);
  font-family: inherit;
  font-size: 12px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
}
.done .check { background: var(--white); color: #000; }

.habit-name { flex: 1; word-break: break-word; }
.streak { font-size: 10px; color: var(--orange); white-space: nowrap; }

.del { background: none; border: 0; color: var(--grey); font-family: inherit; font-size: 12px; cursor: pointer; }
.del:hover { color: var(--red); }

.chip-label { margin: 16px 0 8px; color: var(--grey); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font-size: 8px; padding: 6px 8px; border-width: 3px; }

/* ---------- FORMS ---------- */
#add-form { display: flex; gap: 12px; }

input[type="text"], input[type="email"], input[type="password"] {
  flex: 1;
  min-width: 0;
  width: 100%;
  background: #000;
  color: var(--white);
  border: 4px solid var(--white);
  font-family: inherit;
  font-size: 12px;
  padding: 8px;
  outline: none;
  border-radius: 0;
}
input[type="text"]:focus, input[type="email"]:focus, input[type="password"]:focus { border-color: var(--yellow); }
#add-form input { width: auto; }

#acct-form { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.btnrow { display: flex; gap: 12px; flex-wrap: wrap; }
.btnrow button { flex: 1; min-width: 120px; font-size: 10px; }

button {
  font-family: inherit;
  font-size: 12px;
  background: #000;
  color: var(--white);
  border: 4px solid var(--white);
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 0;
}
button:hover, button:focus-visible { color: var(--yellow); border-color: var(--yellow); outline: none; }
button:disabled { color: var(--grey); border-color: #444; cursor: default; }
.wide { width: 100%; }
.small { font-size: 9px; }
.small-btn { font-size: 9px; padding: 6px 8px; border-width: 3px; }
.note { color: #bbb; line-height: 1.8; margin: 8px 0 12px; }

.chk { display: flex; align-items: center; gap: 10px; margin: 16px 0 4px; cursor: pointer; }
.chk input { width: 18px; height: 18px; accent-color: #ffff00; flex-shrink: 0; }

/* ---------- FOCUS TIMER ---------- */
.focus-top { display: flex; align-items: center; justify-content: center; gap: 24px; margin-bottom: 16px; }
#sprout { width: 96px; height: 96px; image-rendering: pixelated; }
#timer { font-size: 32px; letter-spacing: 2px; }

.presets { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 16px; }
.preset { padding: 8px 10px; }
.preset.sel { color: var(--yellow); border-color: var(--yellow); }

.egg-row { display: flex; align-items: center; gap: 16px; margin: 20px 0 12px; }
#egg { width: 40px; height: 48px; image-rendering: pixelated; }
.egg-info { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.egg-info .bar { flex: none; }

/* ---------- SHARED LIST HEADERS ---------- */
.shop-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 8px; }
.qgap { margin-top: 24px; }

/* ---------- SHOP ---------- */
#shop-tabs, #lb-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.stab { font-size: 9px; padding: 8px; }
.stab.active { color: var(--yellow); border-color: var(--yellow); }

#shop-list, #egg-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }

.card {
  border: 4px solid var(--white);
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}
.card.equipped { border-color: var(--yellow); }
.card .pv { width: 60px; height: 60px; image-rendering: pixelated; }
.cname { font-size: 10px; word-break: break-word; }
.cdesc { font-size: 8px; color: #bbb; line-height: 1.6; }
.card button { width: 100%; font-size: 10px; padding: 6px 4px; }
.sil { filter: brightness(0) invert(0.25); }

/* egg cards */
#egg-list { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.card .egg-pv { width: 40px; height: 48px; image-rendering: pixelated; }
.card .bar { width: 100%; flex: none; height: 12px; }
.pool { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; }
.pool canvas { width: 28px; height: 28px; image-rendering: pixelated; }

/* ---------- QUESTS ---------- */
.qlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.qlist li { border: 4px solid #444; padding: 10px; display: flex; gap: 12px; align-items: center; }
.qlist li.ready { border-color: var(--yellow); }
.qlist li.claimed { color: var(--grey); }
.qinfo { flex: 1; min-width: 0; }
.qname { font-size: 10px; }
.qdesc { font-size: 8px; color: #bbb; margin-top: 4px; line-height: 1.6; }
.qprog { font-size: 8px; color: var(--xp); margin-top: 6px; }
.qbtn { font-size: 9px; padding: 6px 8px; border-width: 3px; white-space: nowrap; }

/* ---------- TROPHIES ---------- */
#trophy-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
#trophy-list li { display: flex; gap: 12px; align-items: flex-start; padding: 8px; border: 4px solid #444; color: var(--grey); }
#trophy-list li.got { border-color: var(--yellow); color: var(--white); }
.tmark { width: 16px; flex-shrink: 0; color: var(--yellow); }
.tname { font-size: 10px; }
.tdesc { font-size: 8px; color: #bbb; margin-top: 4px; }
li:not(.got) .tdesc { color: var(--grey); }
.treward { margin-left: auto; font-size: 8px; color: var(--yellow); white-space: nowrap; }
li:not(.got) .treward { color: var(--grey); }

/* ---------- CAVERN ---------- */
.dex { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 20px; }
.dex canvas { width: 36px; height: 36px; image-rendering: pixelated; }

.day { margin-bottom: 16px; }
.day-head { display: flex; justify-content: space-between; font-size: 9px; margin-bottom: 8px; color: #ddd; }
.field {
  position: relative;
  border: 4px solid var(--frame);
  background-color: #14101f;
  background-image:
    linear-gradient(90deg, rgba(255,255,255,0.04) 4px, transparent 4px),
    linear-gradient(rgba(255,255,255,0.04) 4px, transparent 4px),
    linear-gradient(0deg, #2a1f45 0, #2a1f45 28px, transparent 28px);
  background-size: 24px 24px, 24px 24px, 100% 100%;
  padding: 12px 12px 36px;
  min-height: 110px;
}
.mons { position: relative; z-index: 2; display: flex; flex-wrap: wrap; gap: 6px; }
.mons button { background: none; border: 0; padding: 0; line-height: 0; }
.mons button:hover canvas { transform: translateY(-4px); }
.mons canvas { width: 48px; height: 48px; image-rendering: pixelated; }
.decor { position: absolute; bottom: 4px; width: 24px; height: 24px; z-index: 1; image-rendering: pixelated; opacity: 0.95; }
.empty-note { color: var(--grey); font-size: 9px; line-height: 1.8; }

/* ---------- LEADERBOARD ---------- */
#lb-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
#lb-list li { display: flex; gap: 10px; padding: 6px 8px; border: 3px solid #333; font-size: 10px; align-items: center; }
#lb-list li.me { border-color: var(--yellow); color: var(--yellow); }
.lb-rank { width: 28px; flex-shrink: 0; }
.lb-name { flex: 1; word-break: break-all; }
.lb-val { color: var(--xp); white-space: nowrap; }
#lb-list li.msg { border: 0; color: var(--grey); font-size: 9px; line-height: 1.8; }

/* ---------- DIALOGUE ---------- */
#dialogue { min-height: 120px; }
#text { margin: 0; white-space: pre-wrap; }

/* ---------- BOTTOM MENU ---------- */
#menu { display: flex; gap: 16px; flex-wrap: wrap; }
.menu-btn { flex: 1; min-width: 120px; }

/* ---------- EFFECTS ---------- */
@keyframes flash {
  0%   { background: #fff; }
  100% { background: #000; }
}
body.flash { animation: flash 0.4s steps(4); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-6px); }
  75%      { transform: translateX(6px); }
}
#game.shake { animation: shake 0.3s steps(4); }

@media (max-width: 480px) {
  html, body { font-size: 10px; }
  .box { padding: 12px; }
  #timer { font-size: 24px; }
  #sprout { width: 80px; height: 80px; }
  .tab { font-size: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
