/* Layout: on a phone, four stacked bands (rank, feed, block switch, one grid) that fill one
   screen without scrolling. On a wide screen, two columns: status on the left, both blocks on
   the right, no switch. Dark first; light is a full theme, chosen by system or by the toggle. */
:root {
  color-scheme: dark;
  --bg: #0b0b10;
  --panel: #171721;
  --panel-hi: #20202d;
  --line: #2b2b3a;
  --fg: #f1efe8;
  --muted: #8f8e9d;
  --dim: #55546a;
  --rank-d: #4f8dff;
  --rank-c: #35d47c;
  --rank-b: #ffcf3a;
  --rank-a: #ff8b2a;
  --rank-s: #ff3d55;
  --rank-ss: #ff4fa8;
  --rank-sss: #c47bff;
  --rank-ultra: #8ff4ff;
  --rank: var(--rank-d);
  --font-display: "Bahnschrift", "Impact", "Arial Black", "Roboto", system-ui, sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --radius: 10px;
  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f3f2f6;
    --panel: #ffffff;
    --panel-hi: #e9e8f0;
    --line: #d7d6e1;
    --fg: #15141c;
    --muted: #6a6977;
    --dim: #aeadba;
    --rank-d: #2d6de0;
    --rank-c: #12985a;
    --rank-b: #c08f00;
    --rank-a: #de6508;
    --rank-s: #dc2540;
    --rank-ss: #d12a84;
    --rank-sss: #8a3fe0;
    --rank-ultra: #0b8fa3;
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f2f6;
  --panel: #ffffff;
  --panel-hi: #e9e8f0;
  --line: #d7d6e1;
  --fg: #15141c;
  --muted: #6a6977;
  --dim: #aeadba;
  --rank-d: #2d6de0;
  --rank-c: #12985a;
  --rank-b: #c08f00;
  --rank-a: #de6508;
  --rank-s: #dc2540;
  --rank-ss: #d12a84;
  --rank-sss: #8a3fe0;
  --rank-ultra: #0b8fa3;
}
[data-rank="D"] { --rank: var(--rank-d); }
[data-rank="C"] { --rank: var(--rank-c); }
[data-rank="B"] { --rank: var(--rank-b); }
[data-rank="A"] { --rank: var(--rank-a); }
[data-rank="S"] { --rank: var(--rank-s); }
[data-rank="SS"] { --rank: var(--rank-ss); }
[data-rank="SSS"] { --rank: var(--rank-sss); }
[data-rank="ULTRASCORE"] { --rank: var(--rank-ultra); }

* { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.3;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  padding-block: env(safe-area-inset-top, 0px) env(safe-area-inset-bottom, 0px);
  padding-left: var(--gutter-l);
  padding-right: var(--gutter-r);
}
button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  touch-action: manipulation;
}
button:focus-visible { outline: 2px solid var(--rank); outline-offset: 2px; }
[hidden] { display: none !important; }
h2 { margin: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app {
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
  padding-block: 10px 12px;
}
.status { display: grid; gap: 12px; align-content: start; }

/* Rank block */
.rank {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0 14px;
  align-items: end;
}
.rank-letter {
  font-family: var(--font-display);
  font-weight: 700;
  font-style: italic;
  font-stretch: condensed;
  font-size: clamp(72px, 24vw, 104px);
  line-height: 0.82;
  letter-spacing: -0.03em;
  color: var(--rank);
  text-shadow: 0 0 28px color-mix(in srgb, var(--rank) 45%, transparent);
  padding-right: 0.08em;
  transform-origin: 40% 70%;
  min-width: 0.9em;
  text-align: center;
  white-space: nowrap;
}
.rank-letter[data-len="2"] { font-size: clamp(50px, 16vw, 70px); letter-spacing: -0.1em; }
.rank-letter[data-len="3"] { font-size: clamp(40px, 12.5vw, 54px); letter-spacing: -0.12em; }
.rank-letter[data-len="stack"] { font-size: clamp(22px, 7vw, 30px); line-height: 0.92; letter-spacing: 0.02em; min-width: 0; }
[data-rank="ULTRASCORE"] .rank-letter { animation: ultra 1.8s ease-in-out infinite alternate; }
@keyframes ultra {
  from { text-shadow: 0 0 18px color-mix(in srgb, var(--rank) 50%, transparent); }
  to { text-shadow: 0 0 34px color-mix(in srgb, var(--rank) 85%, transparent), 0 0 60px color-mix(in srgb, var(--rank) 35%, transparent); }
}
.rank-letter.slam { animation: slam 320ms cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes slam {
  0% { transform: scale(1.9) rotate(-6deg); opacity: 0; }
  55% { transform: scale(0.94) rotate(0); opacity: 1; }
  100% { transform: scale(1); }
}
.rank-side { display: grid; gap: 6px; min-width: 0; }
.rank-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.rank-word {
  font-family: var(--font-display);
  font-weight: 700;
  font-stretch: condensed;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 15px;
  color: var(--rank);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tools { display: flex; align-items: center; gap: 6px; flex: none; }
.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 8px;
  color: var(--muted);
  background: var(--panel);
}
/* theme button: auto = sun outline with an A, dark = moon, light = sun */
#themeBtn .sun, #themeBtn .moon, #themeBtn .auto { display: none; }
#themeBtn[data-theme-mode="auto"] .auto { display: block; }
#themeBtn[data-theme-mode="dark"] .moon { display: block; }
#themeBtn[data-theme-mode="light"] .sun { display: block; }
#themeBtn:not([data-theme-mode="auto"]) { color: var(--fg); background: var(--panel-hi); }
/* feedback button: all = speaker with waves, haptic = buzzing phone, off = crossed speaker */
#fbBtn .all, #fbBtn .haptic, #fbBtn .off { display: none; }
#fbBtn[data-feedback="all"] .all { display: block; }
#fbBtn[data-feedback="haptic"] .haptic { display: block; }
#fbBtn[data-feedback="off"] .off { display: block; }
#fbBtn:not([data-feedback="off"]) { color: var(--fg); background: var(--panel-hi); }
.chip {
  height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--fg);
  color: var(--bg);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 12px;
}
.style-num { display: flex; align-items: baseline; gap: 6px; font-variant-numeric: tabular-nums; }
.style-now { font-family: var(--font-display); font-weight: 700; font-size: 30px; line-height: 1; }
.style-next { color: var(--muted); font-size: 13px; }
.meter { height: 12px; background: var(--panel); border-radius: 6px; overflow: hidden; position: relative; }
.meter-fill {
  height: 100%;
  width: 0%;
  background: var(--rank);
  border-radius: 6px;
  transition: width 260ms cubic-bezier(.2, .8, .2, 1);
  box-shadow: 0 0 14px color-mix(in srgb, var(--rank) 60%, transparent);
}

/* Feed */
.feed { position: relative; display: grid; gap: 2px; min-height: 78px; align-content: start; }
.drop, .feed-empty {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 0;
}
.drop { color: var(--dim); }
.drop b { color: var(--muted); font-weight: 700; }
.feed-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.feed-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 0;
  border-bottom: 1px solid var(--line);
  min-width: 0;
  color: var(--muted);
}
.feed-list li:first-child { color: var(--fg); }
.feed-list li:nth-child(n+3) { color: var(--dim); }
.feed-list li:nth-child(n+4) { display: none; }   /* phones: the last three */
.feed-list li .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed-list li .v { font-variant-numeric: tabular-nums; flex: none; }
.feed-list li.new { animation: dropin 220ms cubic-bezier(.2, 1.2, .3, 1) both; }
@keyframes dropin {
  from { transform: translateY(-10px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* Block switch (phones) */
.blocks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  background: var(--panel);
  border-radius: 12px;
}
.blocks [role="tab"] {
  height: 40px;
  border-radius: 9px;
  font-family: var(--font-display);
  font-weight: 700;
  font-stretch: condensed;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 15px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.blocks [role="tab"][aria-selected="true"] { background: var(--fg); color: var(--bg); }
.count {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--panel-hi);
  color: var(--muted);
  display: inline-grid;
  place-items: center;
  font-variant-numeric: tabular-nums;
}
[aria-selected="true"] .count { background: var(--rank); color: var(--bg); }

/* Panels: on phones only the selected block is shown; titles are for wide screens */
.panels { display: grid; min-height: 0; }
.panel { display: grid; grid-template-rows: minmax(0, 1fr); min-height: 0; }
.panel-title { display: none; }
.panels[data-block="daily"] .panel[data-block="chores"],
.panels[data-block="chores"] .panel[data-block="daily"] { display: none; }

/* Action grid */
.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: 8px;
  min-height: 0;
}
.act {
  position: relative;
  min-height: 0;
  min-width: 0;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid transparent;
  transition: transform 90ms ease, background 120ms ease;
}
.act .hit {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: stretch;
  text-align: left;
  padding: 9px 9px 8px;
  border-radius: inherit;
  overflow: hidden;
}
.act:has(.hit:active) { transform: scale(0.95); background: var(--panel-hi); }
.act.punch { animation: punch 260ms cubic-bezier(.2, 1.6, .4, 1); }
@keyframes punch {
  0% { transform: scale(0.9); }
  60% { transform: scale(1.04); }
  100% { transform: none; }
}
.act .name {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: clamp(11px, 3.1vw, 13px);
  line-height: 1.15;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.act .sub {
  display: block;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.86em;
  letter-spacing: 0.08em;
  margin-top: 2px;
}
.act .val {
  align-self: flex-end;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(18px, 5.5vw, 24px);
  line-height: 1;
  color: var(--rank);
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.act .val small {
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
}
/* take-back control: shows on any button tapped today, removes its latest tap.
   Bottom-left, so the label keeps its full width and the value keeps its corner. */
.act .x {
  position: absolute;
  bottom: 4px;
  left: 4px;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
  background: var(--panel-hi);
}
.act .x:active { background: var(--rank); color: var(--bg); }
.act.stale { background: color-mix(in srgb, var(--panel) 70%, var(--bg)); }
.act.stale .name { color: var(--muted); }
.act.spent { background: transparent; border-color: var(--line); color: var(--dim); }
.act.spent .name, .act.spent .sub { color: var(--dim); }
.act.spent .val { color: var(--dim); font-size: 12px; font-family: var(--font-body); letter-spacing: 0.1em; }
.act.spent .x { background: transparent; color: var(--dim); }
.act.spent:has(.hit:active) { transform: scale(0.97); background: var(--panel); }

/* Rank-up flash */
.flash { position: fixed; inset: 0; pointer-events: none; background: var(--rank); opacity: 0; }
.flash.on { animation: flash 420ms ease-out both; }
@keyframes flash { 0% { opacity: 0.55; } 100% { opacity: 0; } }

/* Narrow phones: the take-back control and a wide "again 12" value share the bottom edge */
@media (max-width: 419px) {
  .act .val small { display: none; }
}

/* Short screens (old small phones): tighten every band so four rows still fit */
@media (max-height: 620px) and (max-width: 899px) {
  .app { gap: 8px; padding-block: 6px 8px; }
  .status { gap: 8px; }
  .rank-letter { font-size: 60px; }
  .rank-letter[data-len="2"] { font-size: 44px; }
  .rank-letter[data-len="3"] { font-size: 34px; }
  .rank-letter[data-len="stack"] { font-size: 19px; }
  .style-now { font-size: 24px; }
  .meter { height: 10px; }
  .feed { min-height: 56px; }
  .feed-list li { font-size: 13px; padding: 2px 0; }
  .blocks [role="tab"] { height: 36px; font-size: 14px; }
  .grid { gap: 6px; }
  .act .hit { padding: 6px 7px 5px; }
  .act .name { font-size: 10.5px; }
  .act .val { font-size: 16px; }
}

/* Wide screens: status column left, both blocks right, no switch; the page may scroll if short */
@media (min-width: 900px) {
  body { overflow: auto; }
  .app {
    max-width: 1180px;
    height: auto;
    min-height: 100%;
    grid-template-columns: 340px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 32px;
    padding-block: 28px 32px;
  }
  .status { position: sticky; top: 28px; align-self: start; gap: 20px; }
  .rank { gap: 0 16px; }
  .rank-letter { font-size: 112px; }
  .rank-letter[data-len="2"] { font-size: 76px; }
  .rank-letter[data-len="3"] { font-size: 58px; }
  .rank-letter[data-len="stack"] { font-size: 32px; }
  .style-now { font-size: 34px; }
  .feed { min-height: 0; }
  .feed-list li:nth-child(n+4) { display: flex; }          /* room for the last eight */
  .feed-list li:nth-child(n+3) { color: var(--muted); }
  .feed-list li:nth-child(n+6) { color: var(--dim); }
  .blocks { display: none; }
  .panels { gap: 28px; align-content: start; }
  .panels[data-block="daily"] .panel[data-block="chores"],
  .panels[data-block="chores"] .panel[data-block="daily"] { display: grid; }
  .panel { grid-template-rows: auto minmax(0, 1fr); gap: 12px; }
  .panel-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-display);
    font-weight: 700;
    font-stretch: condensed;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 16px;
    color: var(--muted);
  }
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); grid-auto-rows: 112px; gap: 10px; }
  .act .hit { padding: 12px 12px 10px; }
  .act .name { font-size: 13px; }
  .act .val { font-size: 26px; }
  .act .hit:hover { background: var(--panel-hi); }
  .act.spent .hit:hover { background: color-mix(in srgb, var(--panel) 50%, transparent); }
}
@media (min-width: 1200px) {
  .grid { grid-template-columns: repeat(6, minmax(0, 1fr)); grid-auto-rows: 120px; }
}

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