:root {
  --bg: #1b2a1f;
  --panel: #f1ecd2;
  --ink: #26301f;
  --muted: #565e46;
  --accent: #5b8c3a;
  --track: #cfc9a6;
  --border: #26301f;
}
* { box-sizing: border-box; }
body {
  margin: 0; padding: 16px; background: var(--bg); color: var(--ink);
  font-family: "Courier New", ui-monospace, monospace;
}
h1, h2 { margin: 0; }
h1 { font-size: 1.3rem; color: var(--panel); }
h2 { font-size: 1rem; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 8px; }
#habits-section > h2 { color: var(--panel); }
.device { max-width: 960px; margin: 0 auto; }
.topbar { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.status { color: #a9b88f; font-size: .8rem; }
.status.error { color: #ff9b8a; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 700px) { .grid { grid-template-columns: 1fr; } }
.card {
  background: var(--panel); border: 3px solid var(--border); border-radius: 10px;
  padding: 14px; box-shadow: 4px 4px 0 rgba(0, 0, 0, .35);
}
.stage-bg {
  background: linear-gradient(#bfe3f2, #e6f4d5);
  border: 2px solid var(--border); border-radius: 8px; margin-bottom: 10px;
}
#creature { display: block; width: 100%; max-width: 320px; margin: 0 auto; }
.name-row { display: flex; justify-content: space-between; align-items: center; }
.char-name { font-weight: bold; font-size: 1.2rem; }
.badge { background: var(--ink); color: var(--panel); padding: 2px 10px; border-radius: 12px; }
.muted { color: var(--muted); font-size: .85rem; margin-bottom: 8px; }
.bar {
  position: relative; height: 20px; background: var(--track);
  border: 2px solid var(--border); border-radius: 10px; overflow: hidden;
}
.bar .fill { height: 100%; width: 0; background: var(--accent); transition: width .6s ease; }
.stats-panel { display: flex; flex-direction: column; }
#stats { flex: 1; display: flex; flex-direction: column; justify-content: space-around; }
.stat-row { display: grid; grid-template-columns: 110px 1fr 3ch; gap: 8px; align-items: center;
  margin-bottom: 0; }
.stat-row .label { text-transform: capitalize; }
.habits { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.habit h3 { margin: 0; font-size: 1rem; }
.habit .cat { color: var(--muted); font-size: .75rem; text-transform: uppercase; margin-bottom: 8px; }
.habit dl { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: .85rem; }
.habit dt { color: var(--muted); }
.habit dd { margin: 0; text-align: right; font-weight: bold; }
.empty { color: #a9b88f; }

.stat-row .value { text-align: right; font-weight: bold; }
.xp-label { display: flex; justify-content: space-between; font-weight: bold; font-size: .85rem;
  margin-bottom: 2px; }
.empty-card { color: var(--muted); font-style: italic; margin: 8px 0; }
.card.empty-card { padding: 20px; }
.tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.tabs button {
  font: inherit; padding: 6px 16px; cursor: pointer; background: var(--track); color: var(--ink);
  border: 3px solid var(--border); border-radius: 8px 8px 0 0;
}
.tabs button[aria-selected="true"] { background: var(--panel); font-weight: bold; }
.tabs button:focus-visible { outline: 3px solid gold; outline-offset: 2px; }
[hidden] { display: none !important; }
.grid-history { display: grid; gap: 16px; }
#history-chart { width: 100%; height: auto; display: block; }
#history-chart .axis { stroke: var(--ink); stroke-width: 2; }
#history-chart .grid { stroke: var(--track); stroke-width: 1; }
#history-chart .tick { fill: var(--muted); font-size: 11px; }
#history-chart .line { fill: none; stroke: var(--accent); stroke-width: 3; }
#history-chart .dot { fill: var(--accent); }
#history-chart .dot.levelup { fill: #e8a33d; stroke: var(--ink); stroke-width: 2; }
#history-chart .dot.evolution { fill: #8e5bd0; stroke: var(--ink); stroke-width: 2; }
.error-msg { color: #9b2c1c; font-style: normal; font-weight: bold; }
.legend { display: flex; gap: 16px; margin: 6px 0 0; font-size: .8rem; color: var(--muted); }
.mark { display: inline-block; width: 10px; height: 10px; border: 2px solid var(--ink); vertical-align: middle; }
.dotmark { background: var(--accent); border-radius: 50%; }
.lumark { background: #e8a33d; border-radius: 50%; }
.evmark { background: #8e5bd0; transform: rotate(45deg) scale(.9); }
@media (max-width: 700px) { #history-chart .tick { font-size: 20px; } }
.timeline { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; }
.timeline li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0;
  border-bottom: 1px dashed var(--track); flex-wrap: wrap; }
.timeline li.evolution .tl-text { font-weight: bold; }
.tl-time { color: var(--muted); font-size: .8rem; }
#panel-history.stale > :not(#history-error),
body.stale .device > :not(.topbar):not(.tabs) { opacity: .55; filter: grayscale(.6); }
.stage-bg.evolving { animation: evolve-flash 1.4s ease-out; }
.stage-bg.evolving #creature { animation: evolve-pop 1.4s ease-out; }
@keyframes evolve-flash {
  0% { filter: brightness(1); } 25% { filter: brightness(3) saturate(0); } 100% { filter: brightness(1); }
}
@keyframes evolve-pop {
  0% { transform: scale(.6); } 40% { transform: scale(1.2); } 100% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .stage-bg.evolving, .stage-bg.evolving #creature { animation: none; }
  .bar .fill { transition: none; }
}
