@font-face {
  font-family: "Press Start 2P";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../assets/fonts/PressStart2P.ttf") format("truetype");
}
@font-face {
  font-family: "VT323";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../assets/fonts/VT323.ttf") format("truetype");
}
@font-face {
  font-family: "Silkscreen";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../assets/fonts/Silkscreen.ttf") format("truetype");
}

:root {
  --stone-dark: #2a2118;
  --stone: #3e3226;
  --stone-mid: #5c4a38;
  --stone-light: #7a6349;
  --stone-highlight: #a89070;
  --parchment: #d4c4a0;
  --parchment-dark: #b8a888;
  --parchment-light: #efe6c8;
  --dialog-parchment: #f5f0d8;
  --dialog-parchment-dark: #d7ccb2;
  --dialog-parchment-light: #fffeef;
  --ink: #1a120a;
  --ink-muted: #4a3c2a;
  --ink-blue: #0000a0;
  --gold: #ffd700;
  --gold-dim: #c9a227;
  --xp-orange: #ff9900;
  --xp-yellow: #ffff00;
  --bar-green: #00c800;
  --bar-green-dark: #008000;
  --bar-track: #1a120a;
  --font-display: "Press Start 2P", "Courier New", monospace;
  --font-ui: "VT323", "Courier New", monospace;
  --tab-h: 68px; /* icon 53 + label + padding */
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: #0d0a07;
  font-family: var(--font-ui);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: none;
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
}

.app {
  width: 100%;
  max-width: 480px;
  min-height: 100%;
  min-height: 100dvh;
  background: linear-gradient(180deg, #3e3226 0%, #2a2118 100%);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* Header */
.header {
  flex-shrink: 0;
  padding: 14px 12px 8px;
  text-align: center;
}
.header h1 {
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--gold);
  text-shadow: 1px 1px 0 #000, -1px 0 0 #000, 1px 0 0 #000, 0 1px 0 #000;
  letter-spacing: 0.5px;
  line-height: 1.4;
}

/* Day strip — chronological, today at far right */
.day-strip-wrap[hidden],
.day-strip-wrap.hidden { display: none !important; }
.page-title {
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--gold);
  text-align: center;
  text-shadow: 1px 1px 0 #000;
  padding: 4px 8px 8px;
  flex-shrink: 0;
}
.page-cap { display: none; }

/* v1.5 home-rows — ported from mockups/v3/home-rows.html */
:root {
  --meta-w: 148px;
  --skill-col: 64px;
  --cell: 34px;
  --cell-gap: 3px;
  --aura: 64px;
}
.main-home {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}
.loop-board {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0 8px 8px;
}
.loop-scroll {
  flex: 1;
  min-height: 0;
  overflow-x: auto; /* shared day history scroll (header + all row cells) */
  overflow-y: auto; /* all habit rows */
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y; /* H → days, V → habit list; no preventDefault on pans */
  padding-bottom: 72px; /* clear FAB so last rows + add affordance reachable */
  scrollbar-width: thin;
}
.loop-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: max-content;
  padding-bottom: 4px;
}

/* Date header — newest (today) on LEFT; aligns with .cells */
.date-header,
.loop-header {
  display: flex;
  align-items: stretch;
  position: sticky;
  top: 0;
  z-index: 5;
  background: linear-gradient(180deg, #3e3226 0%, #2a2118 100%);
  padding-bottom: 6px;
  min-height: 36px;
}
.date-spacer,
.loop-header .loop-meta {
  width: calc(var(--meta-w) + 2px);
  flex-shrink: 0;
  position: sticky;
  left: 0;
  z-index: 12;
  background: #2a2118;
  box-shadow: 2px 0 0 #2a2118; /* cover scrolled content under the seam */
}
.dates,
.loop-cells {
  display: flex;
  gap: var(--cell-gap);
  padding: 0 4px 0 5px;
  flex-shrink: 0;
  align-items: center;
  position: relative;
  z-index: 1;
}
.date,
.loop-date {
  width: var(--cell);
  min-width: var(--cell);
  max-width: var(--cell);
  flex: 0 0 var(--cell);
  flex-shrink: 0;
  text-align: center;
  font-family: var(--font-display);
  font-size: 6px;
  color: var(--parchment);
  text-shadow: 1px 1px 0 #000;
  line-height: 1.2;
  padding-top: 2px;
  border: none;
  scroll-snap-align: start;
  box-sizing: border-box;
}
.date.today,
.loop-date.today {
  color: var(--gold);
  /* box-shadow (not outline) so it cannot paint over the sticky meta column */
  outline: none;
  box-shadow: inset 0 0 0 2px #c9a227;
  background: rgba(201, 162, 39, 0.18);
  position: relative;
  z-index: 0;
}
.date .dow,
.loop-date .d-wd,
.loop-date .dow { display: block; }
.date .num,
.loop-date .d-num,
.loop-date .num {
  font-family: var(--font-ui);
  font-size: 14px;
  display: block;
  margin-top: 1px;
  color: inherit;
}

.row,
.loop-row {
  display: flex;
  align-items: stretch;
  background: var(--parchment);
  border: 2px solid #2a2118;
  box-shadow:
    inset 1px 1px 0 var(--parchment-dark),
    inset -1px -1px 0 var(--parchment-light);
  min-height: 58px;
  width: max-content;
  max-width: none;
  overflow: visible;
}

.meta,
.loop-meta {
  width: var(--meta-w);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px 4px 4px;
  border-right: 1px solid var(--parchment-dark);
  overflow: visible;
  position: sticky;
  left: 0;
  z-index: 10;
  background: var(--parchment); /* opaque — covers day cells sliding underneath */
  box-sizing: border-box;
  box-shadow: 3px 0 0 var(--parchment);
}

.skill-wrap,
.loop-sprite-wrap {
  position: relative;
  width: var(--skill-col);
  height: var(--skill-col);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  z-index: 0;
}

/* Streak aura — design/fx/README.md (sheet 512×64, 8 frames @ 64px)
   Fixed 64×64, centred on skill-wrap (behind sprite), independent of sprite native size. */
.streak-aura,
.loop-aura {
  display: none;
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--aura);
  height: var(--aura);
  transform: translate(-50%, -50%);
  background: url("../assets/fx/streak-aura.png") 0 0 no-repeat;
  background-size: 512px 64px; /* native 1× sheet — frame N at -N*64px */
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  z-index: 0;
  pointer-events: none;
  animation: streak-aura-spin 0.64s steps(8) infinite;
  border-radius: 0;
  box-shadow: none;
  margin: 0;
}
.skill-wrap.is-streak .streak-aura,
.loop-sprite-wrap.is-streak .streak-aura,
.loop-sprite-wrap.is-streak .loop-aura {
  display: block;
}
.skill-sprite,
.loop-sprite {
  position: relative;
  z-index: 1;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  outline: 1px solid #1a120a;
  outline-offset: 0;
  display: block;
  box-sizing: content-box;
  /* native 1× — do not scale; flex-shrink 0 so row height cannot squash art */
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  flex-shrink: 0;
}

.info,
.loop-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  z-index: 1;
  padding: 2px 2px 2px 0;
}
.name,
.loop-name {
  font-family: var(--font-display);
  font-size: 7px;
  color: var(--ink);
  line-height: 1.3;
  max-height: calc(7px * 1.3 * 2);
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  word-break: break-word;
  white-space: normal;
  text-overflow: unset;
}
.loop-name-row { display: contents; } /* streak moves to lv-row */
.xp-bar,
.loop-xp {
  height: 4px;
  background: #1a120a;
  border: 1px solid #5c4a38;
  width: 100%;
  max-width: 100%;
  align-self: stretch;
  border-radius: 0;
  overflow: hidden;
  flex-shrink: 0;
  box-sizing: border-box;
}
.xp-bar > i,
.loop-xp > i {
  display: block;
  height: 100%;
  background: linear-gradient(180deg, #ffe566 0%, #ffd700 45%, #c9a227 100%);
  width: 0%;
}
.lv-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}
.lv,
.loop-lv {
  font-family: var(--font-display);
  font-size: 6px;
  color: var(--gold);
  background: #1a120a;
  padding: 1px 3px;
  text-shadow: 1px 1px 0 #000;
  border: 1px solid #5c4a38;
  white-space: nowrap;
}
.streak-badge,
.loop-streak-badge {
  display: none;
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1;
  color: #ff9900;
  text-shadow: 1px 0 0 #000, -1px 0 0 #000, 0 1px 0 #000, 0 -1px 0 #000;
  white-space: nowrap;
  align-items: center;
}
.streak-badge.is-on,
.loop-streak-badge.is-on {
  display: inline-flex;
}
.streak-badge[hidden],
.loop-streak-badge[hidden] { display: none !important; }

.cells {
  display: flex;
  gap: var(--cell-gap);
  align-items: center;
  padding: 6px 4px 6px 5px;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}
.cell,
.loop-cell {
  /* 34×34 cell; 18×18 mark centred ⇒ 8px inset on each side (mockup home-rows) */
  width: var(--cell);
  min-width: var(--cell);
  max-width: var(--cell);
  height: var(--cell);
  min-height: var(--cell);
  flex: 0 0 var(--cell);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-sizing: border-box;
  background-color: #c8b890;
  background-image: none;
  border: 2px solid;
  border-color: #efe6c8 #5c4a38 #5c4a38 #efe6c8;
  box-shadow: inset 1px 1px 0 #efe6c8, 0 0 0 1px #2a2118;
  font-size: 0;
  color: transparent;
  line-height: 0;
  overflow: visible; /* never clip the 18×18 mark */
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.cell .glyph,
.loop-cell .glyph {
  /* v23: glyph art unchanged (18×18); box = min(18px, cell − 2px borders − 2×4px margin),
     whole px (--cell is integer), scaled down with contain if a cell is ever smaller. */
  width: min(18px, calc(var(--cell) - 12px));
  height: min(18px, calc(var(--cell) - 12px));
  max-width: none;
  max-height: none;
  object-fit: contain;
  object-position: center;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  flex-shrink: 0;
  pointer-events: none;
}
.cell.miss,
.loop-cell.mark-miss,
.loop-cell.miss {
  background-color: #c8b890;
}
.cell.pause,
.loop-cell.mark-pause,
.loop-cell.pause {
  background-color: #c8b890;
}
.cell.done,
.loop-cell.mark-done,
.loop-cell.done {
  background-color: #b8d0a0;
}
.cell.today-col,
.loop-cell.today-col {
  /* inset ring only — no outline (avoids painting over sticky meta) */
  box-shadow:
    inset 1px 1px 0 #efe6c8,
    0 0 0 1px #2a2118,
    inset 0 0 0 2px #c9a227;
  outline: none;
  position: relative;
  z-index: 0;
}

@keyframes streak-aura-spin {
  from { background-position: 0 0; }
  to   { background-position: -512px 0; }
}
@media (prefers-reduced-motion: reduce) {
  .streak-aura,
  .loop-aura {
    animation: none;
    background-position: 0 0; /* static frame 0 */
    transform: translate(-50%, -50%);
  }
}

.day-strip-wrap {
  flex-shrink: 0;
  position: relative;
  padding: 4px 0 10px;
}
.day-strip {
  display: flex;
  flex-direction: row;
  gap: 6px;
  padding: 0 10px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.day-strip::-webkit-scrollbar { display: none; }
.day {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  background: var(--parchment);
  border: 2px solid;
  border-color: var(--stone-highlight) #1a120a #1a120a var(--stone-highlight);
  box-shadow: inset 1px 1px 0 var(--parchment-light);
  border-radius: 999px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 9px;
  color: var(--ink);
  line-height: 1.05;
  cursor: pointer;
  padding: 0;
  position: relative;
}
.day .dow { font-size: 9px; }
.day .date {
  font-family: var(--font-ui);
  font-size: 15px;
  color: var(--ink-muted);
  margin-top: 1px;
}
.day.selected {
  background: linear-gradient(180deg, #ffd700 0%, #c9a227 100%);
  border-color: #1a120a;
  box-shadow: inset 1px 1px 0 #ffe566, 0 2px 0 #1a120a;
  color: #1a120a;
  text-shadow: none;
}
.day.selected .date { color: #1a120a; }
/* Subtle today marker when not selected */
.day.is-today:not(.selected) {
  box-shadow: inset 1px 1px 0 var(--parchment-light), 0 0 0 2px rgba(255, 215, 0, 0.55);
}
.day.is-today:not(.selected)::after {
  content: "";
  position: absolute;
  bottom: 4px;
  left: 50%;
  width: 5px;
  height: 5px;
  margin-left: -2.5px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 1px #1a120a;
}
.today-jump {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  font-family: var(--font-display);
  font-size: 8px;
  padding: 8px 10px;
  background: linear-gradient(180deg, #ffd700 0%, #c9a227 100%);
  border: 2px solid #1a120a;
  box-shadow: 0 2px 0 #1a120a, inset 1px 1px 0 #ffe566;
  color: #1a120a;
  cursor: pointer;
  border-radius: 2px;
}
.today-jump.hidden { display: none; }

/* Main */
.main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 10px calc(var(--tab-h) + 72px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.habit-card {
  position: relative;
  background: var(--parchment);
  border: 3px solid #2a2118;
  box-shadow:
    inset 2px 2px 0 var(--parchment-dark),
    inset -2px -2px 0 var(--parchment-light),
    0 0 0 1px var(--stone-light);
  padding: 8px 8px 14px;
  display: grid;
  grid-template-columns: 56px 1fr;
  column-gap: 8px;
  row-gap: 2px;
  align-items: center;
}
.habit-card .skill {
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.habit-card .skill-sprite {
  width: 40px;
  height: 40px;
  image-rendering: pixelated;
  background: #000;
  border: 2px solid;
  border-color: #1a120a var(--stone-highlight) var(--stone-highlight) #1a120a;
  box-shadow: inset 1px 1px 0 #000;
  object-fit: contain;
}
.habit-card .lv {
  font-family: var(--font-display);
  font-size: 7px;
  color: var(--gold);
  background: #1a120a;
  padding: 2px 3px;
  line-height: 1.2;
  text-shadow: 1px 1px 0 #000;
  white-space: nowrap;
  border: 1px solid #5c4a38;
}
.habit-card .meta { grid-column: 2; align-self: end; min-width: 0; }
.habit-card .name {
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--ink);
  letter-spacing: 0.3px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.habit-card .streak {
  font-family: var(--font-ui);
  font-size: 17px;
  color: var(--ink-muted);
  line-height: 1.1;
}
.habit-card .streak strong { color: var(--ink); }
.habit-card .xp-next {
  grid-column: 2;
  align-self: start;
  font-family: var(--font-ui);
  font-size: 15px;
  color: #6a4010;
}

/* Option 4 — bevelled stone channel + gold fill (Pixel mockup v2) */
.stone-channel {
  grid-column: 1 / -1;
  --segs: 7;
  --done: 0;
  width: 100%;
  height: 28px;
  margin-top: 8px;
  margin-bottom: 2px;
  position: relative;
  background: #2a2118;
  border: 3px solid;
  border-color: #1a120a #a89070 #a89070 #1a120a;
  box-shadow:
    inset 2px 2px 0 #1a120a,
    inset -1px -1px 0 #5c4a38,
    0 0 0 1px #3e3226;
  cursor: pointer;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  display: block;
}
.stone-channel .gold-fill {
  position: absolute;
  left: 3px;
  top: 3px;
  bottom: 3px;
  width: calc((100% - 6px) * var(--done) / var(--segs));
  max-width: calc(100% - 6px);
  background: linear-gradient(180deg, #ffe566 0%, #ffd700 35%, #c9a227 70%, #8a7010 100%);
  box-shadow:
    inset 0 1px 0 #fff3a0,
    inset 0 -1px 0 #8a7010;
  pointer-events: none;
  transition: width 120ms steps(1);
}
.stone-channel.is-empty .gold-fill { width: 0; }
.stone-channel .carved {
  position: absolute;
  inset: 3px;
  pointer-events: none;
  background: repeating-linear-gradient(
    to right,
    transparent 0,
    transparent calc(100% / var(--segs) - 1px),
    rgba(168, 144, 112, 0.45) calc(100% / var(--segs) - 1px),
    rgba(168, 144, 112, 0.45) calc(100% / var(--segs))
  );
}
.stone-channel .bevel-top {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 2px;
  background: #1a120a;
  opacity: 0.8;
  pointer-events: none;
}
.stone-channel .mark {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 12px;
  color: transparent;
  z-index: 2;
  pointer-events: none;
  text-shadow: none;
}
.stone-channel.day-done .mark {
  color: #fff;
  text-shadow: 1px 1px 0 #000, -1px 0 0 #000, 1px 0 0 #000, 0 0 4px #ff9900;
}
.stone-channel.is-full {
  box-shadow:
    inset 2px 2px 0 #1a120a,
    inset -1px -1px 0 #5c4a38,
    0 0 0 1px #3e3226,
    0 0 0 2px rgba(255, 215, 0, 0.35);
}

.habit-card .xp-bar {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 4px;
  height: 5px;
  background: var(--bar-track);
  border: 1px solid #1a120a;
  overflow: hidden;
}
.habit-card .xp-bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(180deg, #ffe566 0%, #ffd700 40%, #c9a227 100%);
  box-shadow: inset 0 1px 0 #fff3a0;
}

/* FAB */
.fab {
  position: absolute;
  right: 14px;
  bottom: calc(var(--tab-h) + 12px + env(safe-area-inset-bottom, 0px));
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(180deg, #ffd700 0%, #c9a227 100%);
  border: 3px solid #1a120a;
  box-shadow:
    0 3px 0 #1a120a,
    inset 1px 1px 0 #ffe566,
    inset -1px -1px 0 #8a7010;
  font-family: var(--font-display);
  font-size: 22px;
  color: #1a120a;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  z-index: 15;
  cursor: pointer;
}
/* Plus glyph placeholder — swap to FX.plusGlyph img when Pixel ships it */
.fab .fab-plus-glyph {
  display: none; /* reserved for drop-in */
  width: 22px;
  height: 22px;
  image-rendering: pixelated;
}

/* Bottom nav — selected/unselected icon assets */
.tab-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px));
  padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0px));
  background: var(--stone-mid);
  border-top: 2px solid var(--stone-highlight);
  box-shadow: inset 0 1px 0 var(--stone-light);
  display: flex;
  align-items: stretch;
  gap: 4px;
  z-index: 20;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--parchment);
}
.tab img,
.tab img.nav-icon {
  /* v23: OSRS tab icon, byte-copied; shared 1.3× (width/height attrs, rounded px), centred on CSS tile */
  object-fit: fill;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  flex-shrink: 0;
}
.tab.is-disabled,
.tab:disabled {
  cursor: default;
  opacity: 0.95;
}
.tab.is-disabled span,
.tab:disabled span {
  color: #8a7a62;
}
.tab span {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--parchment);
  text-shadow: 1px 1px 0 #000;
  line-height: 1;
}
.tab.active span,
.tab[aria-current="page"] span { color: var(--gold); }
.tab:not(.active):not([aria-current="page"]) span { color: var(--parchment); }
.tab.active,
.tab[aria-current="page"] { filter: none; }
.tab:not(.active):not([aria-current="page"]) img { opacity: 0.92; }


.placeholder {
  padding: 24px 16px;
  text-align: center;
  color: var(--ink);
  font-size: 20px;
  background: var(--parchment);
  border: 3px solid #2a2118;
  box-shadow:
    inset 2px 2px 0 var(--parchment-dark),
    inset -2px -2px 0 var(--parchment-light);
}
.placeholder strong {
  font-family: var(--font-display);
  font-size: 11px;
  display: block;
  margin-bottom: 8px;
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.68);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.overlay.hidden { display: none; }
.overlay.center {
  align-items: center;
  background: rgba(0, 0, 0, 0.55);
}

/* Add-habit sheet (stone mid, SPEC) */
.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--stone-mid);
  border-top: 3px solid var(--stone-highlight);
  box-shadow: 0 -4px 24px #000, inset 0 1px 0 var(--stone-light);
  padding: 10px 12px calc(18px + env(safe-area-inset-bottom, 0px));
  max-height: 85%;
  overflow-y: auto;
}
.sheet .grab {
  width: 40px;
  height: 4px;
  background: var(--stone-light);
  margin: 0 auto 10px;
  border: 1px solid #1a120a;
}
.sheet h2 {
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--gold);
  text-shadow: 1px 1px 0 #000;
  text-align: center;
  margin-bottom: 12px;
}
.field { margin-bottom: 10px; }
.field label {
  display: block;
  font-family: var(--font-display);
  font-size: 8px;
  color: var(--parchment);
  text-shadow: 1px 1px 0 #000;
  margin-bottom: 4px;
}
.field .hint {
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--stone-highlight);
  margin-top: 3px;
}
.input, .select {
  width: 100%;
  background: var(--parchment);
  border: 2px solid;
  border-color: #1a120a var(--stone-highlight) var(--stone-highlight) #1a120a;
  box-shadow: inset 1px 1px 0 var(--parchment-dark);
  padding: 8px 10px;
  font-family: var(--font-ui);
  font-size: 20px;
  color: var(--ink);
}
.skill-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.skill-row img {
  width: 36px;
  height: 36px;
  image-rendering: pixelated;
  background: #000;
  border: 2px solid #1a120a;
  flex-shrink: 0;
}
.skill-row .select { flex: 1; }

.seg {
  display: flex;
  gap: 4px;
}
.seg button {
  flex: 1;
  font-family: var(--font-display);
  font-size: 10px;
  padding: 10px 0;
  background: var(--stone);
  border: 2px solid;
  border-color: var(--stone-highlight) #1a120a #1a120a var(--stone-highlight);
  color: var(--parchment);
  text-shadow: 1px 1px 0 #000;
  cursor: pointer;
}
.seg button.on {
  background: #6a553f;
  border-color: #1a120a var(--stone-highlight) var(--stone-highlight) #1a120a;
  color: var(--gold);
}

.sheet-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.btn {
  flex: 1;
  padding: 12px 8px;
  font-family: var(--font-display);
  font-size: 10px;
  border: 2px solid;
  cursor: pointer;
  line-height: 1.2;
}
.btn-cancel {
  background: var(--stone);
  border-color: var(--stone-highlight) #1a120a #1a120a var(--stone-highlight);
  color: var(--parchment);
  text-shadow: 1px 1px 0 #000;
}
.btn-save {
  background: linear-gradient(180deg, #ffd700, #c9a227);
  border-color: #1a120a;
  color: #1a120a;
  box-shadow: inset 1px 1px 0 #ffe566;
}

/* Level-up / weekly parchment dialog */
.fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}
.spark {
  position: absolute;
  width: 4px;
  height: 4px;
  animation: burst 2s ease-out infinite;
}
.spark:nth-child(1) { left: 18%; top: 22%; background: #ffd700; --dx: -28px; --dy: 48px; }
.spark:nth-child(2) { left: 78%; top: 18%; background: #ff9900; --dx: 30px; --dy: 40px; animation-delay: 0.3s; }
.spark:nth-child(3) { left: 50%; top: 14%; background: #ffff00; --dx: 0; --dy: 52px; animation-delay: 0.15s; }
.spark:nth-child(4) { left: 30%; top: 36%; background: #00c800; --dx: -36px; --dy: 28px; animation-delay: 0.5s; }
.spark:nth-child(5) { left: 70%; top: 40%; background: #ff5722; --dx: 24px; --dy: 36px; animation-delay: 0.7s; }
.spark:nth-child(6) { left: 12%; top: 48%; background: #4fc3f7; --dx: -18px; --dy: 22px; animation-delay: 0.4s; }
@keyframes burst {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0.3); opacity: 0; }
}

.parchment-dialog {
  position: relative;
  z-index: 2;
  width: min(328px, calc(100% - 24px));
  background: var(--dialog-parchment);
  border: 3px solid #262518;
  box-shadow:
    0 0 0 2px #6a6151,
    0 0 0 4px #9d9071,
    0 0 0 5px #262518,
    inset 2px 2px 0 var(--dialog-parchment-light),
    inset -2px -2px 0 var(--dialog-parchment-dark),
    0 10px 28px rgba(0, 0, 0, 0.55);
  padding: 14px 12px 12px;
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 10px 12px;
  align-items: center;
  animation: dialogPop 0.25s ease-out;
}
.parchment-dialog .icon {
  width: 52px;
  height: 52px;
  background: #000;
  border: 2px solid #262518;
  image-rendering: pixelated;
  object-fit: contain;
}
.parchment-dialog .copy {
  font-family: var(--font-ui);
  font-size: 18px;
  color: var(--ink-blue);
  line-height: 1.25;
}
.parchment-dialog .copy .line2 { margin-top: 4px; }
.parchment-dialog .copy .bonus {
  margin-top: 6px;
  color: #6a4010;
}
.parchment-dialog .copy .bonus em {
  font-style: normal;
  color: #8a4a00;
  font-family: var(--font-display);
  font-size: 9px;
}
.parchment-dialog .continue {
  grid-column: 1 / -1;
  text-align: center;
  font-family: var(--font-ui);
  font-size: 17px;
  color: var(--ink-blue);
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid var(--dialog-parchment-dark);
  cursor: pointer;
  text-decoration: underline;
}
.popup-caption {
  position: absolute;
  bottom: 28px;
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--font-display);
  font-size: 8px;
  color: var(--gold);
  text-shadow: 1px 1px 0 #000;
  z-index: 2;
  pointer-events: none;
}
@keyframes dialogPop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--tab-h) + 80px);
  transform: translateX(-50%);
  z-index: 30;
  background: rgba(0, 0, 0, 0.88);
  border: 2px solid var(--gold);
  padding: 8px 12px;
  text-align: center;
  max-width: 280px;
  pointer-events: none;
}
.toast.hidden { display: none; }
.toast .t-title {
  font-family: var(--font-display);
  font-size: 9px;
  color: var(--gold);
  text-shadow: 1px 1px 0 #000;
}
.toast .t-body {
  font-size: 17px;
  color: #fff;
  margin-top: 2px;
}

.xp-float {
  position: absolute;
  z-index: 35;
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--xp-yellow);
  text-shadow: 2px 2px 0 #000, -1px 0 0 #000, 1px 0 0 #000, 0 0 6px #ff9900;
  pointer-events: none;
  animation: xpFloat 1.2s ease-out forwards;
}
@keyframes xpFloat {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(-40px); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .parchment-dialog, .xp-float, .spark { animation: none !important; }
}

.hidden { display: none !important; }


/* Backup panel (Equip tab) */
.backup-panel {
  background: var(--parchment);
  border: 3px solid #2a2118;
  box-shadow:
    inset 2px 2px 0 var(--parchment-dark),
    inset -2px -2px 0 var(--parchment-light),
    0 0 0 1px var(--stone-light);
  padding: 12px 12px 14px;
}
.backup-title {
  font-family: var(--font-display);
  font-size: 11px;
  color: #5a3010;
  margin-bottom: 6px;
  text-align: center;
}
.backup-hint {
  font-size: 16px;
  color: var(--ink-muted);
  line-height: 1.25;
  margin-bottom: 10px;
}
.backup-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.backup-actions .btn { flex: 1; }
.backup-divider {
  height: 2px;
  background: var(--parchment-dark);
  margin: 10px 0 12px;
}
.backup-file-label {
  display: block;
  font-family: var(--font-display);
  font-size: 8px;
  color: #5a3010;
  margin: 8px 0 4px;
}
#importFile {
  width: 100%;
  font-family: var(--font-ui);
  font-size: 16px;
  color: var(--ink);
  margin-bottom: 6px;
}
.backup-paste {
  min-height: 88px;
  resize: vertical;
  margin-bottom: 8px;
}
#btnImportPaste {
  width: 100%;
  margin-top: 4px;
}
.backup-status {
  margin-top: 10px;
  font-size: 15px;
  color: #5a3010;
  min-height: 1.2em;
}
.backup-status.is-error { color: #8b1a1a; }
.backup-status.is-ok { color: #1a5a1a; }


/* Inventory — flat #756550 + Pixel border PNGs, invisible 4×7, cell52 icons
   Fits viewport: no page scroll; icon size via --inv-icon (whole px). */
.main-inv {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden !important;
  padding: 0 8px calc(var(--tab-h) + env(safe-area-inset-bottom, 0px) + 6px) !important;
  gap: 0;
  position: relative;
}
.main-inv.hidden { display: none !important; }
.main-inv .page-title {
  flex-shrink: 0;
  padding: 2px 8px 6px;
}
.inv-panel {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  /* v23: OSRS empty inventory panel (design/sprites/extras/interface/Inventory_tab.png, byte-copied)
     as a 9-slice frame: slice 8px on all sides, drawn at 2× (16px), pixelated. */
  background: none;
  border-style: solid;
  border-width: 16px;
  border-image-source: url("../assets/items/inventory_panel.png");
  border-image-slice: 8 fill;
  border-image-width: 16px;
  border-image-repeat: stretch;
  box-shadow: none;
  padding: 2px;
  display: flex;
  flex-direction: column;
  image-rendering: pixelated;
}
.inv-panel-inner {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.inv-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(7, 1fr);
  gap: 4px 4px;
  flex: 1;
  min-height: 0;
  align-content: stretch;
  touch-action: none;
}
.inv-slot {
  position: relative;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 0;
  cursor: default;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.inv-slot.filled { cursor: grab; }
.inv-slot.dragging { opacity: 0.35; }
.inv-slot.drop-target {
  outline: 1px dashed rgba(255, 215, 0, 0.55);
  outline-offset: -2px;
}
.inv-slot img {
  /* cell52 sprites — whole-number --inv-icon (default 52) for crisp pixels */
  width: var(--inv-icon, 52px);
  height: var(--inv-icon, 52px);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  object-fit: fill;
  pointer-events: none;
}
.inv-slot .qty {
  position: absolute;
  top: 2px;
  left: 4px;
  z-index: 2;
  font-family: var(--font-display);
  font-size: 9px;
  color: #ffff00;
  line-height: 1;
  text-shadow:
    1px 0 0 #000, -1px 0 0 #000, 0 1px 0 #000, 0 -1px 0 #000,
    1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
  pointer-events: none;
}
.inv-slot.selected {
  outline: 2px solid #ffd700;
  outline-offset: 0;
  background: rgba(0, 0, 0, 0.25);
}

/* Tap item panel (mockup inventory-item-panel) */
.inv-scrim {
  position: absolute;
  inset: 0;
  background: #00000099;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 30;
}
.inv-scrim.hidden { display: none !important; }
.item-panel {
  width: 100%;
  max-width: 300px;
  background: var(--dialog-parchment);
  border: 4px solid #262518;
  box-shadow:
    0 0 0 2px #6a6151,
    0 0 0 4px #9d9071,
    0 0 0 5px #262518,
    inset 2px 2px 0 #efe6c8,
    inset -2px -2px 0 #b8a888;
  padding: 14px 12px 12px;
}
.item-panel .iname {
  font-family: var(--font-display);
  font-size: 10px;
  color: #0000a0;
  text-align: center;
  margin-bottom: 8px;
  line-height: 1.35;
}
.item-panel .item-preview {
  width: 72px;
  height: 72px;
  margin: 0 auto 10px;
  background: #756550;
  border: 2px solid #1a120a;
  display: flex;
  align-items: center;
  justify-content: center;
}
.item-panel .item-preview img {
  image-rendering: pixelated;
  width: 52px;
  height: 52px;
  object-fit: fill;
}
.item-panel .iblurb {
  font-size: 17px;
  color: #1a120a;
  text-align: center;
  margin-bottom: 12px;
  line-height: 1.2;
  white-space: pre-line;
}
.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-bottom: 10px;
}
.item-actions .btn {
  flex: 1;
  min-width: 100px;
}
.item-actions .btn:disabled {
  opacity: 0.45;
  pointer-events: none;
}
.inv-drag-ghost {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translate(-50%, -50%);
  opacity: 0.92;
}
.inv-drag-ghost img {
  width: 52px;
  height: 52px;
  image-rendering: pixelated;
}

/* Equip screen — no page scroll; .equip-fit scales to viewport */
.main-equip {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  overflow: hidden !important;
  padding: 0 8px calc(var(--tab-h) + env(safe-area-inset-bottom, 0px) + 6px) !important;
}
.main-equip.hidden { display: none !important; }
.main-equip .page-title {
  flex-shrink: 0;
  padding: 2px 8px 4px;
}
.equip-fit-host {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
  display: flex;
  justify-content: center;
}
.equip-fit {
  transform-origin: top center;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  will-change: transform;
}
.equip-panel {
  background: #58483a;
  border: 2px solid;
  border-color: var(--stone-highlight) #1a120a #1a120a var(--stone-highlight);
  box-shadow: inset 1px 1px 0 var(--stone-light), inset -1px -1px 0 #1a120a;
  padding: 8px 4px 10px;
  flex-shrink: 0;
  width: 100%;
}
.equip-title {
  font-family: var(--font-display);
  font-size: 8px;
  color: #ffb000;
  text-shadow: 1px 1px 0 #000;
  text-align: center;
  margin-bottom: 6px;
}
.equip-doll {
  position: relative;
  width: 288px;
  height: 380px;
  margin: 0 auto;
  max-width: 100%;
}
.equip-doll .lines {
  position: absolute;
  left: 36px;
  top: 66px;
  /* lines.png 107×146 @ 2× */
  width: 214px;
  height: 292px;
  image-rendering: pixelated;
  pointer-events: none;
  z-index: 0;
}
.equip-slot {
  position: absolute;
  /* slot_*.png 32×32 @ 2× */
  width: 64px;
  height: 64px;
  z-index: 1;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
.equip-slot img.box {
  width: 64px;
  height: 64px;
  image-rendering: pixelated;
  display: block;
  pointer-events: none;
}
.equip-slot .equipped {
  /* trimmed sprite @ 1×, centred; slot outline stays visible behind */
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  /* v29: JS sets width/height = round(natural × 1.3) (EQUIPPED_ITEM_SCALE); no max cap */
  width: auto;
  height: auto;
  image-rendering: pixelated;
  object-fit: fill;
  z-index: 2;
  pointer-events: none;
}
/* v30: filled slots swap their tile to Pixel's blank slot_empty.png (JS), drawn at the same 2× as
   the other tiles (.equip-slot img.box 64px, pixelated). v29's stone-square overlay removed. */
.equip-slot.s-head   { left: 112px; top: 0; }
.equip-slot.s-cape   { left: 30px;  top: 78px; }
.equip-slot.s-neck   { left: 112px; top: 78px; }
.equip-slot.s-ammo   { left: 194px; top: 78px; }
.equip-slot.s-weapon { left: 0;     top: 156px; }
.equip-slot.s-body   { left: 112px; top: 156px; }
.equip-slot.s-shield { left: 224px; top: 156px; }
.equip-slot.s-legs   { left: 112px; top: 236px; }
.equip-slot.s-hands  { left: 0;     top: 316px; }
.equip-slot.s-feet   { left: 112px; top: 316px; }
.equip-slot.s-ring   { left: 224px; top: 316px; }

.equip-below {
  display: flex;
  align-items: stretch;
  gap: 8px;
  flex-shrink: 0;
}
.equip-char-wrap {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: #58483a;
  border: 2px solid;
  border-color: var(--stone-highlight) #1a120a #1a120a var(--stone-highlight);
  padding: 6px 8px;
}
.equip-char-wrap img {
  /* character.png 72×190 @ 2× */
  width: 144px;
  height: 380px;
  image-rendering: pixelated;
  object-fit: fill;
  display: block;
}
.equip-stats {
  flex: 1;
  min-width: 0;
  background: var(--parchment);
  border: 3px solid #2a2118;
  box-shadow: inset 2px 2px 0 var(--parchment-dark), inset -2px -2px 0 var(--parchment-light);
  padding: 8px;
  display: flex;
  flex-direction: column;
}
.equip-stats h2 {
  font-family: var(--font-display);
  font-size: 8px;
  color: var(--ink);
  text-align: center;
  margin-bottom: 6px;
}
.equip-stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 17px;
  color: var(--ink);
  border-bottom: 1px solid #b8a888;
  padding: 3px 0;
}
.equip-stat .k { color: #4a3c2a; }
.equip-stat .v {
  font-family: var(--font-display);
  font-size: 9px;
  color: #0000a0;
}
.equip-pick {
  background: var(--parchment);
  border: 3px solid #2a2118;
  padding: 10px;
  flex-shrink: 0;
}
.equip-pick-title {
  font-family: var(--font-display);
  font-size: 9px;
  color: #5a3010;
  text-align: center;
  margin-bottom: 8px;
}
.equip-pick-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
  max-height: 180px;
  overflow-y: auto;
}
.equip-pick-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  font-family: var(--font-ui);
  font-size: 18px;
  padding: 6px 8px;
  background: #efe6c8;
  border: 2px solid #2a2118;
  color: var(--ink);
  cursor: pointer;
}
.equip-pick-item img {
  width: auto;
  height: auto;
  max-width: 34px;
  max-height: 48px;
  object-fit: fill;
  image-rendering: pixelated;
}


/* Backup opens as overlay so Equip/Inventory stay no-scroll */
.backup-open-btn {
  flex-shrink: 0;
  align-self: center;
  margin: 2px 0 4px;
  font-family: var(--font-display);
  font-size: 8px;
  color: var(--gold);
  background: var(--stone);
  border: 2px solid;
  border-color: var(--stone-highlight) #1a120a #1a120a var(--stone-highlight);
  padding: 6px 14px;
  cursor: pointer;
  text-shadow: 1px 1px 0 #000;
  z-index: 2;
}
.backup-overlay {
  position: absolute;
  inset: 0;
  z-index: 35;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.backup-overlay.hidden { display: none !important; }
.backup-overlay .backup-panel {
  width: 100%;
  max-width: 480px;
  max-height: min(85dvh, 640px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0;
  border-radius: 0;
  border-top: 3px solid var(--stone-highlight);
}
.backup-overlay .backup-close-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 6px;
}


/* —— Skill page (Smithing) — ported from mockups/v3/smithing.html —— */
.skill-page {
  position: absolute;
  inset: 0;
  z-index: 25;
  background: linear-gradient(180deg, #3e3226 0%, #2a2118 100%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.skill-page.hidden { display: none !important; }
.skill-page-header {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 6px;
  padding: 12px 10px 8px;
  text-align: center;
}
.skill-back {
  width: 36px;
  height: 32px;
  font-family: var(--font-display);
  font-size: 14px;
  line-height: 1;
  color: var(--gold);
  background: var(--stone-mid);
  border: 2px solid;
  border-color: var(--stone-highlight) #1a120a #1a120a var(--stone-highlight);
  cursor: pointer;
  text-shadow: 1px 1px 0 #000;
}
.skill-page-titles h1 {
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--gold);
  text-shadow: 1px 1px 0 #000, -1px 0 0 #000, 1px 0 0 #000, 0 1px 0 #000;
  line-height: 1.3;
}
.skill-page-titles .sub {
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--parchment);
  text-shadow: 1px 1px 0 #000;
  margin-top: 4px;
}
.skill-page-lv {
  font-family: var(--font-display);
  font-size: 6px;
  color: var(--gold);
  background: #1a120a;
  padding: 3px 5px;
  border: 1px solid #5c4a38;
  text-shadow: 1px 1px 0 #000;
  white-space: nowrap;
}
.skill-tabs {
  display: flex;
  gap: 6px;
  padding: 0 12px 8px;
  flex-shrink: 0;
}
.skill-tab-btn {
  flex: 1;
  height: 32px;
  font-family: var(--font-display);
  font-size: 8px;
  background: var(--stone-mid);
  color: var(--parchment);
  border: 2px solid var(--stone-dark);
  box-shadow: inset 1px 1px 0 var(--stone-highlight);
  text-shadow: 1px 1px 0 #000;
  cursor: pointer;
}
.skill-tab-btn.active {
  background: var(--parchment);
  color: var(--ink);
  border-color: var(--gold-dim);
  box-shadow: inset 1px 1px 0 var(--parchment-light), 0 0 0 1px var(--gold-dim);
  text-shadow: none;
}
.skill-fx-row {
  display: flex;
  justify-content: center;
  padding: 0 0 4px;
  flex-shrink: 0;
  min-height: 128px;
}
/* Craft FX — v27: 2× whole-number scale (128px frames), still pixelated, steps(8) intact. */
.furnace-smelt,
.anvil-hammer {
  width: 128px;
  height: 128px;
  position: relative;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  box-sizing: border-box;
  flex-shrink: 0;
  border: none;
  box-shadow: none;
}
.furnace-smelt {
  background: url("../assets/fx/furnace-still.png") center / 128px 128px no-repeat;
}
.furnace-smelt.is-loop,
.furnace-smelt.is-playing {
  background: url("../assets/fx/furnace-smelt.png") 0 0 no-repeat;
  background-size: 1024px 128px; /* 8×64 sheet @ 2× */
  animation: furnace-smelt-sheet 0.8s steps(8) infinite;
}
.furnace-smelt.is-playing {
  animation-iteration-count: 1;
}
@keyframes furnace-smelt-sheet {
  from { background-position: 0 0; }
  to   { background-position: -1024px 0; }
}
.anvil-hammer {
  border: none;
  background: url("../assets/fx/anvil/option-a.png") 0 0 no-repeat;
  background-size: 1024px 128px; /* 8×64 sheet @ 2× */
  box-shadow: none;
}
.anvil-hammer.is-loop,
.anvil-hammer.is-playing {
  animation: anvil-hammer-sheet 0.8s steps(8) infinite;
}
.anvil-hammer.is-playing {
  animation-iteration-count: 1;
}
@keyframes anvil-hammer-sheet {
  from { background-position: 0 0; }
  to   { background-position: -1024px 0; }
}
@media (prefers-reduced-motion: reduce) {
  .furnace-smelt.is-loop,
  .furnace-smelt.is-playing {
    animation: none !important;
    background: url("../assets/fx/furnace-still.png") center / 128px 128px no-repeat !important;
  }
  .anvil-hammer.is-loop,
  .anvil-hammer.is-playing {
    animation: none !important;
    background-position: 0 0; /* static frame 0 */
  }
}
.skill-panel {
  flex: 1;
  min-height: 0;
  margin: 0 10px 12px;
  padding: 10px 8px 12px;
  background: var(--parchment);
  border: 3px solid #2a2118;
  box-shadow:
    inset 2px 2px 0 var(--parchment-light),
    inset -2px -2px 0 var(--parchment-dark),
    0 0 0 1px var(--stone-highlight);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.skill-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px 6px;
}
.skill-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #c8b890;
  border: 2px solid;
  border-color: #efe6c8 #5c4a38 #5c4a38 #efe6c8;
  box-shadow: inset 1px 1px 0 #efe6c8, 0 0 0 1px #2a2118;
  padding: 4px 2px 3px;
  min-height: 78px;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
.skill-tile .icon {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.skill-tile .icon img {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  width: auto;
  height: auto;
  max-width: 52px;
  max-height: 52px;
  object-fit: fill;
}
/* Locked: silhouette — brightness(0), opacity ~0.85 (not mockup 0.55) */
.skill-tile.locked {
  cursor: default;
  pointer-events: none;
}
.skill-tile.locked .icon img {
  filter: brightness(0);
  opacity: 0.85;
}
.skill-tile .lv {
  font-family: var(--font-display);
  font-size: 7px; /* v27: was 6px */
  color: var(--ink);
  margin-top: 2px;
  text-align: center;
  line-height: 1.2;
}
/* v27: high-contrast labels — OSRS yellow / light grey on dark backing + shadow */
.skill-tile .lv {
  background: #1a140c;
  padding: 2px 3px;
  text-shadow: 1px 1px 0 #000;
}
.skill-tile.locked .lv { color: #d8d0c0; }
.skill-tile.unlocked .lv { color: #ffff00; }
.skill-tile.unlocked .icon img,
.craft-scrim .item-preview img {
  filter: drop-shadow(1px 0 0 #000) drop-shadow(-1px 0 0 #000) drop-shadow(0 1px 0 #000) drop-shadow(0 -1px 0 #000);
}
.craft-costs { list-style: none; margin: 0 0 10px; padding: 0; font-size: 17px; color: #1a120a; text-align: center; line-height: 1.25; }
.craft-costs .short { color: #a00000; }
.craft-costs .have { color: #1a5a1a; }
#craftConfirmMake:disabled { opacity: 0.45; filter: grayscale(1); cursor: not-allowed; }
.skill-stub {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: var(--parchment);
  font-size: 18px;
  text-align: center;
  text-shadow: 1px 1px 0 #000;
}
.skill-stub.hidden { display: none !important; }
/* Craft success uses level-up parchment; hide fireworks caption noise */
.parchment-dialog.is-craft .icon {
  width: auto;
  height: auto;
  max-width: 52px;
  max-height: 52px;
  object-fit: fill;
  image-rendering: pixelated;
}
.popup-caption.is-craft-hide { visibility: hidden; }

/* Add-habit skill picker — one habit per skill */
.skill-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 6px;
}
.skill-pick {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px 4px;
  background: var(--parchment-light);
  border: 2px solid;
  border-color: var(--stone-highlight) #1a120a #1a120a var(--stone-highlight);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--ink);
  line-height: 1.1;
  min-height: 58px;
}
.skill-pick img {
  width: 28px;
  height: 28px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
}
.skill-pick.is-on {
  background: linear-gradient(180deg, #ffd700 0%, #c9a227 100%);
  border-color: #1a120a;
  box-shadow: inset 1px 1px 0 #ffe566;
  color: #1a120a;
}
.skill-pick.is-used {
  /* disabled look but still tappable */
  filter: grayscale(1) brightness(0.78);
  opacity: 0.72;
  color: #5c4a38;
}
.skill-pick.is-used.is-on {
  filter: none;
  opacity: 1;
}
.skill-row .select[hidden] { display: none !important; }

/* Stats — OSRS skills grid, fit viewport (no scroll) like Inventory */
.main-stats {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden !important;
  padding: 0 10px calc(var(--tab-h) + 16px);
  gap: 0;
}
.main-stats.hidden { display: none !important; }
.main-stats .page-title { flex-shrink: 0; }
.stats-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #3a3228;
  border: 3px solid #1a120a;
  box-shadow:
    inset 1px 1px 0 #6a5a48,
    inset -1px -1px 0 #1a120a,
    0 0 0 1px #5c4a38;
  padding: 4px;
}
.stats-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 1fr;
  gap: 2px;
  align-content: stretch;
}
.stats-tile {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px;
  background: linear-gradient(180deg, #5a4e40 0%, #3e342a 100%);
  border: 1px solid #1a120a;
  box-shadow: inset 1px 1px 0 #7a6a55;
  cursor: default;
  min-height: 0;
  overflow: hidden;
}
.stats-tile.is-added { cursor: pointer; }
.stats-tile.is-added:active { filter: brightness(1.08); }
.stats-tile.is-unadded {
  filter: grayscale(1) brightness(0.72);
  opacity: 0.85;
}
.stats-tile img {
  width: auto;
  height: auto;
  max-width: 28px;
  max-height: 28px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  flex-shrink: 0;
  background: #000;
}
.stats-levels {
  display: flex;
  flex-direction: column;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 8px;
  line-height: 1.15;
  color: #ffd700;
  text-shadow: 1px 1px 0 #000;
  min-width: 0;
}
.stats-levels .cur { color: #ffd700; }
.stats-levels .sep {
  align-self: stretch;
  height: 1px;
  background: #1a120a;
  margin: 1px 0;
  transform: rotate(-12deg);
  transform-origin: center;
}
.stats-levels .max { color: #ffd700; }
.stats-tile.is-total {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0a0a0a;
  border: 2px solid #c9a227;
  box-shadow: inset 0 0 0 1px #5c4a20;
  filter: none;
  opacity: 1;
  cursor: default;
}
.stats-tile.is-total .stats-total-label {
  font-family: var(--font-display);
  font-size: 6px;
  color: #ffd700;
  text-shadow: 1px 1px 0 #000;
  margin-bottom: 4px;
}
.stats-tile.is-total .stats-total-val {
  font-family: var(--font-display);
  font-size: 11px;
  color: #ffd700;
  text-shadow: 1px 1px 0 #000;
}

/* v18 coins: 10-frame 52px sheet, scaled with --inv-icon */
.inv-slot .coin-icon {
  display: block;
  width: var(--inv-icon, 52px);
  height: var(--inv-icon, 52px);
  background: url('../assets/items/coins_sheet_cell52.png') no-repeat;
  background-size: calc(var(--inv-icon, 52px) * 10) var(--inv-icon, 52px);
  background-position: calc(var(--inv-icon, 52px) * var(--coin-frame, 0) * -1) 0;
  image-rendering: pixelated;
  pointer-events: none;
}
.inv-slot .qty.qty-white { color: #ffffff; }
.inv-slot .qty.qty-green { color: #00ff80; }
img.coin-detail {
  object-fit: none;
  object-position: calc(var(--coin-frame, 0) * -52px) 0;
  width: 52px !important;
  height: 52px !important;
}

/* v18 skill icons: identical square box per usage; frame from sheet, 1× (no scaling) */
img.skill-icon {
  width: var(--box) !important;
  height: var(--box) !important;
  max-width: none !important;
  max-height: none !important;
  object-fit: none !important;
  object-position: calc(var(--frame, 0) * var(--box) * -1) 0 !important;
  image-rendering: pixelated;
}
/* add-sheet icon keeps its 36px outer size: 32px box + 2px border */
#habitSkillIcon.skill-icon { box-sizing: content-box; }

/* v22 nav: identical rounded stone tile per tab (CSS), icon centred; red tile when selected */
.tab .nav-tile {
  width: 52px;
  height: 52px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 8px;
  border: 2px solid #1a120a;
  background: linear-gradient(180deg, #5d5447 0%, #4a4237 55%, #3b342b 100%);
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.16), inset -2px -2px 0 rgba(0, 0, 0, 0.38);
}
.tab.active .nav-tile,
.tab[aria-current="page"] .nav-tile {
  background: linear-gradient(180deg, #c14839 0%, #b94737 45%, #8f3428 100%);
  box-shadow: inset 2px 2px 0 rgba(255, 200, 180, 0.28), inset -2px -2px 0 rgba(40, 10, 8, 0.5);
}
.tab:not(.active):not([aria-current="page"]) img { opacity: 1; }

/* v23: pin the WHOLE header strip (blank left cell + dates) above sticky row metas; solid opaque bg */
.loop-header {
  z-index: 13; /* above sticky row metas (10/12), below tab bar (20) and overlays (25+) */
  background: #2a2118;
  box-shadow: 0 2px 0 #1a120a;
}
.loop-header .loop-meta {
  z-index: 14;
  background: #2a2118;
}

/* v24: 1px black OSRS-style outline on inventory item sprites (CSS only) */
.inv-slot img,
.inv-slot .coin-icon,
.equip-slot img.equipped {
  filter: drop-shadow(1px 0 0 #000) drop-shadow(-1px 0 0 #000) drop-shadow(0 1px 0 #000) drop-shadow(0 -1px 0 #000);
}

/* v25 Stats = OSRS skills panel (ref design/sprites/extras/interface/Skills_tab.png; colours sampled) */
.main-stats .stats-panel {
  background: #3e3529;           /* gap colour between slots (62,53,41) */
  border: 2px solid #000;
  box-shadow: inset 1px 1px 0 #877f6c, inset -1px -1px 0 #4f4836;
  padding: 4px;
  gap: 4px;
  position: relative;
}
.main-stats .stats-grid {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(8, 1fr);
  grid-auto-rows: unset;
  gap: 4px;
}
.skill-slot {
  --r: 7px;
  position: relative;
  display: flex;
  align-items: center;
  min-height: 0;
  min-width: 0;
  padding: 0 6px 0 4px;
  border: none;
  background: #2e2b23;           /* outer dark rim (46,43,35) */
  cursor: pointer;
  overflow: hidden;
  -webkit-mask:
    radial-gradient(circle at 0 0, transparent var(--r), #000 calc(var(--r) + 0.5px)) top left / 51% 51% no-repeat,
    radial-gradient(circle at 100% 0, transparent var(--r), #000 calc(var(--r) + 0.5px)) top right / 51% 51% no-repeat,
    radial-gradient(circle at 0 100%, transparent var(--r), #000 calc(var(--r) + 0.5px)) bottom left / 51% 51% no-repeat,
    radial-gradient(circle at 100% 100%, transparent var(--r), #000 calc(var(--r) + 0.5px)) bottom right / 51% 51% no-repeat;
          mask:
    radial-gradient(circle at 0 0, transparent var(--r), #000 calc(var(--r) + 0.5px)) top left / 51% 51% no-repeat,
    radial-gradient(circle at 100% 0, transparent var(--r), #000 calc(var(--r) + 0.5px)) top right / 51% 51% no-repeat,
    radial-gradient(circle at 0 100%, transparent var(--r), #000 calc(var(--r) + 0.5px)) bottom left / 51% 51% no-repeat,
    radial-gradient(circle at 100% 100%, transparent var(--r), #000 calc(var(--r) + 0.5px)) bottom right / 51% 51% no-repeat;
}
.skill-slot::before {
  content: '';
  position: absolute;
  inset: 2px;
  --r: 6px;
  background: #4d4d49;           /* stone fill (77,77,73) */
  box-shadow: inset 1px 1px 0 #726451, inset -1px -1px 0 #26231c;
  -webkit-mask: inherit;
          mask: inherit;
  z-index: 0;
}
.skill-slot.is-tip::before { background: #5a5a55; }
.skill-slot > * { position: relative; z-index: 1; }
.skill-slot img.skill-icon { flex-shrink: 0; filter: none; opacity: 1; }
.skill-slot .slot-lv {
  flex: 1;
  align-self: stretch;
  display: grid;
  grid-template-rows: 1fr 1fr;
  font-family: var(--font-display);
  font-size: 11px;
  line-height: 1;
  text-shadow: 1px 1px 0 #000;
  position: relative;
  padding: 8px 0;
}
.skill-slot .slot-lv .cur { justify-self: start; align-self: start; padding-left: 6px; }
.skill-slot .slot-lv .max { justify-self: end; align-self: end; }
.skill-slot .slot-lv .slash {
  position: absolute; left: 50%; top: 50%;
  width: 26px; height: 2px; background: #000;
  transform: translate(-50%, -50%) rotate(-55deg);
}
.skill-slot.is-added .slot-lv { color: #ffff00; }
.skill-slot.is-unadded .slot-lv { color: #9a9a9a; }
.stats-total {
  flex-shrink: 0;
  background: #000;
  border: 1px solid #2e2b23;
  border-radius: 4px;
  color: #ffff00;
  font-family: var(--font-display);
  font-size: 11px;
  text-align: center;
  padding: 8px 4px;
  text-shadow: 1px 1px 0 #000;
}
.osrs-tooltip {
  position: absolute;
  z-index: 5;
  background: #ffffa0;           /* OSRS cream tooltip */
  border: 1px solid #000;
  color: #000;
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.05;
  padding: 3px 6px;
  white-space: nowrap;
  pointer-events: none;
}

/* ---------- v30 General Store ---------- */
.inv-title-row { position: relative; flex-shrink: 0; min-height: 30px; display: flex; align-items: center; justify-content: center; }
.inv-title-row .page-title { padding: 2px 8px; }
.inv-title-row .shop-open {
  /* neutral text button: SpriteBot has no shop icon sprite */
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  flex: none;
  padding: 5px 8px;
  font-size: 9px;
  line-height: 1;
  background: var(--stone);
  border-color: var(--stone-highlight) #1a120a #1a120a var(--stone-highlight);
  color: var(--gold);
  text-shadow: 1px 1px 0 #000;
}
.shop-scrim { align-items: stretch; padding: 8px 0; }
.shop-window {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* same byte-copied OSRS panel (Inventory_tab.png) 9-slice frame as the bag, 2×, pixelated */
  border-style: solid;
  border-width: 16px;
  border-image-source: url("../assets/items/inventory_panel.png");
  border-image-slice: 8 fill;
  border-image-width: 16px;
  border-image-repeat: stretch;
  image-rendering: pixelated;
  padding: 2px 4px 4px;
  overflow: hidden;
}
.shop-head { display: flex; align-items: center; justify-content: center; position: relative; min-height: 28px; }
.shop-title {
  font-family: var(--font-display);
  font-size: 11px;
  color: #ff981f; /* OSRS interface title orange */
  text-shadow: 1px 1px 0 #000;
}
.shop-head .shop-close { position: absolute; right: 0; top: 0; flex: none; padding: 6px 8px; font-size: 9px; }
.shop-coins, .shop-restock {
  font-family: var(--font-display);
  font-size: 8px;
  color: #ffff00;
  text-shadow: 1px 1px 0 #000;
  text-align: center;
  margin: 4px 0 6px;
}
.shop-restock { color: #c8b98f; margin: 6px 0 0; }
.shop-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  flex-shrink: 0;
}
.shop-slot {
  position: relative;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  padding: 0;
  cursor: pointer;
}
.shop-slot.selected { border-color: #ffd700; }
.shop-slot.sold-out img, .shop-slot.sold-out .item-noart { opacity: 0.4; }
.shop-slot img {
  width: 52px;
  height: 52px;
  image-rendering: pixelated;
  object-fit: fill;
  pointer-events: none;
  filter: drop-shadow(1px 0 0 #000) drop-shadow(-1px 0 0 #000) drop-shadow(0 1px 0 #000) drop-shadow(0 -1px 0 #000);
}
/* OSRS stock number: yellow, top-left, 1px black outline (same as bag stack labels) */
.shop-slot .qty {
  position: absolute;
  top: 2px;
  left: 3px;
  z-index: 2;
  font-family: var(--font-display);
  font-size: 9px;
  color: #ffff00;
  line-height: 1;
  text-shadow:
    1px 0 0 #000, -1px 0 0 #000, 0 1px 0 #000, 0 -1px 0 #000,
    1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
  pointer-events: none;
}
/* v30 no-art fallback: item name text in the slot (SpriteBot sprite missing; no art drawn/edited) */
.item-noart {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border: 1px dashed #c8b98f;
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1;
  color: #fff;
  text-align: center;
  text-shadow: 1px 1px 0 #000;
  word-break: break-word;
  overflow: hidden;
  pointer-events: none;
}
.inv-slot .item-noart { width: var(--inv-icon, 52px); height: var(--inv-icon, 52px); }
.item-preview .item-noart { color: #1a120a; text-shadow: none; border-color: #1a120a; font-size: 14px; }
.shop-detail { max-width: none; margin-top: 8px; padding: 8px 10px; flex-shrink: 0; }
.shop-detail.hidden { display: none !important; }
.shop-detail .iname { margin-bottom: 4px; }
.shop-detail-row { display: flex; align-items: center; gap: 12px; justify-content: center; }
.shop-detail .item-preview { margin: 0; flex: none; }
.shop-price, .shop-stock { font-size: 18px; color: #1a120a; line-height: 1.2; }
.shop-buy { display: flex; gap: 8px; margin-top: 8px; }
.shop-buy .btn { flex: 1; padding: 8px 4px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.shop-buy .btn .sub { font-family: var(--font-ui); font-size: 14px; line-height: 1; }
.shop-buy .btn.unavailable {
  background: #8b8476;
  border-color: #5c574d;
  color: #3a372f;
  box-shadow: none;
  cursor: not-allowed;
}
.shop-note { min-height: 20px; margin-top: 6px; font-size: 16px; color: #8b0000; text-align: center; line-height: 1.2; }
.shop-note.ok { color: #0b5d0b; }
