/* Hoki - a calm little shrine for a waving lucky cat.
   Visual language follows Jeda: warm paper, white cards, serif display type, one gold accent,
   flat layered scenes. See design.md for the tokens. */

:root {
  --bg: #f6f2eb;
  --surface: #ffffff;
  --surface-2: #f0ebe2;
  --line: #e6dfd3;
  --text: #26221d;
  --muted: #6b6157;
  --gold: #d9a441;          /* fills only */
  --gold-ink: #8a6418;      /* gold text on light surfaces (AA) */
  --red: #b7443a;
  --radius: 20px;
  --radius-sm: 14px;
  --shadow: 0 1px 2px rgba(60, 45, 25, 0.06), 0 12px 32px rgba(60, 45, 25, 0.1);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Noto Serif", "Noto Serif SC", "Songti SC", "SimSun", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --ring: #e7dccb;
  --halo: rgba(217, 164, 65, 0.16);
  --sky-top: #b4cddd;
  --sky-mid: #e4ece9;
  --sky-low: #f6efe0;
  --orb: #fff6d6;
  --hill-far: #c4cdb0;
  --hill-mid: #adbb98;
  --hill-near: #95a685;
  --temple: #75816a;
  --temple-edge: #9aa58c;
  --cloud: rgba(255, 255, 255, 0.7);
  --temple-light: #ffcf7a;
  --star-opacity: 0;
  color-scheme: light;
}

:root[data-time="dawn"] {
  --sky-top: #6d5a86;
  --sky-mid: #e0a183;
  --sky-low: #f6d5a8;
  --orb: #ffd08a;
  --hill-far: #a98f8a;
  --hill-near: #7d6f73;
  --temple: #5d5160;
  --hill-mid: #957d80;
  --temple-edge: #8a7a86;
  --cloud: rgba(255, 228, 210, 0.55);
}

:root[data-time="dusk"] {
  --sky-top: #3d3160;
  --sky-mid: #c46f62;
  --sky-low: #f2b27a;
  --orb: #ffcf86;
  --hill-far: #8b6470;
  --hill-near: #5e4a5c;
  --temple: #45374a;
  --hill-mid: #755666;
  --temple-edge: #6a5670;
  --cloud: rgba(255, 210, 190, 0.35);
}

:root[data-time="night"] {
  --sky-top: #182038;
  --sky-mid: #2a3456;
  --sky-low: #414b70;
  --orb: #f4efd8;
  --hill-far: #343d5c;
  --hill-near: #262d46;
  --temple: #1c2238;
  --star-opacity: 0.85;
  --hill-mid: #2d3552;
  --temple-edge: #2f3756;
  --cloud: rgba(255, 255, 255, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1512;
    --surface: #241e1a;
    --surface-2: #2f2721;
    --line: #3d332b;
    --text: #efe9e0;
    --muted: #b0a596;
    --gold-ink: #e8be6a;
    --ring: #3a332b;
    --halo: rgba(217, 164, 65, 0.12);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
  .scene {
    filter: brightness(0.92) saturate(0.9);
  }
  /* Dark mode by day: a quiet twilight inside the gate instead of a bright noon sky on a dark page. */
  :root[data-time="day"] {
    --sky-top: #2e3a55;
    --sky-mid: #56627d;
    --sky-low: #8a8790;
    --orb: #efe6c8;
    --hill-far: #4d5848;
    --hill-mid: #414c3e;
    --hill-near: #363f34;
    --temple: #262c25;
    --temple-edge: #3f4a3c;
    --cloud: rgba(255, 255, 255, 0.12);
    --star-opacity: 0.45;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 16px calc(32px + env(safe-area-inset-bottom));
  background: transparent;
  overflow-x: hidden;
}

html {
  /* The warm dawn glow lives on the root so it spans the full window at every width. */
  background:
    radial-gradient(ellipse 90% 42% at 50% -6%, rgba(232, 200, 120, 0.42), transparent 70%),
    var(--bg);
  background-attachment: fixed;
}

@media (prefers-color-scheme: dark) {
  html {
    background:
      radial-gradient(ellipse 60% 26% at 50% -6%, rgba(232, 190, 110, 0.13), transparent 70%),
      var(--bg);
  }
}

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

/* Keyboard focus traces Hoki's own silhouette in gold (a ~3 px contour plus a soft glow), so the ring hugs the cat
   instead of boxing the moon gate. The transparent outline stays for Windows high-contrast mode, where it turns solid. */
.cat:focus-visible {
  outline: 3px solid transparent;
  outline-offset: 2px;
}

.cat:focus-visible > svg,
.cat:focus-visible > canvas {
  filter:
    drop-shadow(1.5px 0 0 var(--gold))
    drop-shadow(-1.5px 0 0 var(--gold))
    drop-shadow(0 1.5px 0 var(--gold))
    drop-shadow(0 -1.5px 0 var(--gold))
    drop-shadow(0 0 10px rgba(217, 164, 65, 0.55));
}

/* ---------- header ---------- */

.top {
  width: 100%;
  max-width: 440px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 2px 4px;
}

.brand {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.5rem;
  letter-spacing: 0.03em;
}

.brand span {
  margin-left: 6px;
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--muted);
  letter-spacing: 0.12em;
}

.sound-btn {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px 0 11px;
  /* Quiet chrome: no frame until hover, serif italic label like the other captions */
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: italic 400 0.95rem var(--serif);
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.sound-btn:hover {
  background: var(--surface);
  border-color: var(--line);
}

.sound-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sound-btn .mute {
  display: none;
}

.sound-btn[aria-pressed="false"] {
  color: var(--muted);
}

.sound-btn[aria-pressed="false"] .wave {
  display: none;
}

.sound-btn[aria-pressed="false"] .mute {
  display: inline;
}

/* ---------- stage: moon gate + cat ---------- */

.stage {
  position: relative;
  /* Fits the phone height too: the stage shrinks before the stats card is pushed off screen. */
  width: clamp(240px, min(82vw, calc((100svh - 350px) / 1.1)), 380px);
  aspect-ratio: 1 / 1.1;
  margin-top: 8px;
}

.scene {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: auto;
  overflow: visible;
}

.scene .sky-top { stop-color: var(--sky-top); }
.scene .sky-mid { stop-color: var(--sky-mid); }
.scene .sky-low { stop-color: var(--sky-low); }
.scene .orb { fill: var(--orb); opacity: 0.95; }
.scene .hill-far { fill: var(--hill-far); }
.scene .hill-near { fill: var(--hill-near); }
.scene .hill-mid { fill: var(--hill-mid); }
.scene .hill-rim { fill: none; stroke: #ffffff; stroke-opacity: 0.28; stroke-width: 1.2; stroke-linecap: round; }
.scene .cloud { fill: var(--cloud); }
.scene .temple .temple-edge { fill: var(--temple-edge); }
.scene .shrub { fill: var(--hill-near); }
.scene .temple { fill: var(--temple); }
.scene .temple .temple-light { fill: var(--temple-light); opacity: 0.85; }
.scene .stars circle { fill: #fff; opacity: var(--star-opacity); }
.scene .gate-halo { fill: var(--halo); }
.scene .gate-ring { fill: none; stroke: var(--ring); stroke-width: 10; }

.scene * {
  transition: fill 2s ease, stop-color 2s ease;
}

.lantern line { stroke: #6b5444; stroke-width: 1.2; }
.lantern .paper { fill: #b6544a; }
.lantern .cap { fill: #d9a441; }
.lantern .rib { fill: none; stroke: #9e3830; stroke-width: 1; opacity: 0.7; }
.lantern .tassel { stroke: #d9a441; stroke-width: 2.4; stroke-linecap: round; }

.lantern {
  transform-box: view-box;
  animation: sway 5.5s ease-in-out infinite;
}

.lantern-left { transform-origin: 70px 0; }
.lantern-right { transform-origin: 250px 0; animation-delay: -2.2s; animation-duration: 6.5s; }

@keyframes sway {
  0%, 100% { transform: rotate(-3deg); }
  50% { transform: rotate(3deg); }
}

.ground {
  position: absolute;
  left: 50%;
  bottom: 0.5%;
  width: 72%;
  height: 7%;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(60, 40, 20, 0.22), transparent);
}

.glow {
  position: absolute;
  left: 50%;
  top: 46%;
  width: 82%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 214, 120, 0.85), rgba(255, 214, 120, 0) 72%);
  opacity: 0;
  pointer-events: none;
}

.cat {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 74%;
  aspect-ratio: 240 / 264;
  transform: translateX(-50%);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  border-radius: 40%;
  transition: transform 0.12s ease;
}

.cat svg,
.cat canvas {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* The moon-gate halo breathes slowly so the scene feels alive before the first tap. */
.scene .gate-halo {
  transform-box: fill-box;
  transform-origin: center;
  animation: halo 4.2s ease-in-out infinite;
}

@keyframes halo {
  0%, 100% { opacity: 0.55; transform: scale(0.985); }
  50% { opacity: 1; transform: scale(1.02); }
}

@media (hover: hover) {
  .cat:hover {
    transform: translateX(-50%) scale(1.012);
  }
}

.cat:active,
.cat.bump {
  transform: translateX(-50%) scale(0.975);
}

.fx {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
}

.float {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 700;
  /* floaters spawn over the scene sky: light gold with a soft dark lift reads at day and night */
  color: #f7d784;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(38, 24, 10, 0.6), 0 0 10px rgba(38, 24, 10, 0.4);
  animation: float-up 1.3s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}

.float.big {
  /* milestone seal: white on vermilion reads on cream and on the night sky */
  font-size: 2.4rem;
  line-height: 1;
  padding: 0.14em 0.22em 0.18em;
  border-radius: 14px;
  color: #fff8ea;
  background: #b7443a;
  box-shadow: 0 0 0 3px #fff8ea, 0 8px 22px rgba(110, 40, 28, 0.35);
  text-shadow: none;
  animation-duration: 2.2s;
}

@keyframes float-up {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.9); }
  12% { opacity: 1; }
  62% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -190%) scale(1.04); }
}

.coin {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #e3b24e;
  box-shadow: inset 0 0 0 1.5px #b98a32;
  animation: coin-fly 1.1s cubic-bezier(0.2, 0.6, 0.4, 1) forwards;
}

.coin::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  transform: translate(-50%, -50%);
  background: #9a7128;
  border-radius: 1px;
}

@keyframes coin-fly {
  0% { opacity: 1; transform: translate(0, 0) scale(0.6); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(1) rotate(200deg); }
}

.hint {
  margin: 10px 0 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1rem;
  color: var(--muted);
  transition: opacity 0.6s ease;
}

.hint.quiet {
  opacity: 0.75;
}

/* ---------- stats card ---------- */

.card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stats {
  margin-top: 14px;
  padding: 18px 20px 14px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 6px 20px;
  align-items: center;
}

.today {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 84px;
}

.today .num {
  font-family: var(--serif);
  font-size: 2.6rem;
  line-height: 1;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.today .label {
  margin-top: 4px;
  font-family: var(--serif);
  font-size: 0.92rem;
  color: var(--muted);
}

.boost-row {
  display: flex;
  justify-content: space-between;
  font-family: var(--serif);
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.boost-row b {
  color: var(--gold-ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #e8c46e, #d9a441);
}

.total {
  grid-column: 1 / -1;
  margin: 8px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 0.8rem;
  color: var(--muted);
}

/* Secondary stats stay secondary: today's count and the boost are the headline. */
.total b {
  color: var(--muted);
  font-weight: 600;
}

.total .dot {
  margin: 0 8px;
}

/* ---------- footer ---------- */

.foot {
  width: 100%;
  max-width: 440px;
  margin-top: 12px;
  text-align: center;
}

.get-label {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.9rem;
  color: var(--muted);
}

.actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.actions .pill {
  padding: 0 14px;
  border-color: var(--line);
  font-size: 0.8rem;
  font-weight: 400;
}

.pill {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: 500 0.85rem var(--sans);
  cursor: pointer;
}

.pill:hover {
  color: var(--text);
}

.pill:hover {
  background: var(--surface);
}

.pill.small {
  min-height: 44px;
  padding: 0 14px;
  background: var(--surface);
}

.panel {
  margin: 12px auto 0;
  padding: 14px 16px;
  text-align: left;
  font-size: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.panel p {
  margin: 0 0 10px;
}

.cmd {
  display: flex;
  gap: 8px;
  align-items: center;
}

.cmd code {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  font: 0.8rem/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace;
  overflow-wrap: anywhere;
}

.fine {
  margin: 12px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

/* ---------- toast ---------- */

.toast {
  position: absolute;
  left: 50%;
  /* Under the cat, over the hint line: never across the lanterns or the header. */
  top: calc(100% - 14px);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 10px;
  width: max-content;
  max-width: min(92vw, 400px);
  padding: 5px 16px 5px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 0.92rem;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 0.35s ease, transform 0.35s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.hint.away {
  opacity: 0;
}

.toast span {
  line-height: 1.35;
}

.toast strong {
  font-weight: 600;
}

.toast b {
  font-family: var(--serif);
  font-size: 1.45rem;
  line-height: 1;
  color: var(--red);
}

@media (prefers-color-scheme: dark) {
  .toast b {
    color: #e8786a;
  }
}

/* ---------- daily fortune ---------- */

.fortune {
  order: 0; /* right after the luck card: today's count and today's fortune read together */
  margin-top: 10px;
  padding: 6px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

.fortune-seal {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--red);
  color: #fff3df;
  font-family: var(--serif);
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: inset 0 0 0 3px rgba(255, 243, 223, 0.35);
}

.fortune-title {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.9rem;
  color: var(--muted);
}

.fortune-name {
  margin-left: 6px;
  font-family: var(--serif);
  font-size: 1rem;
  letter-spacing: 0;
  color: var(--red);
  text-transform: none;
}

.fortune-line {
  margin: 2px 0 0;
  text-wrap: pretty;
  font-family: var(--serif);
  font-size: 0.98rem;
  line-height: 1.35;
  color: var(--muted);
}

.fortune-text {
  flex: 1;
}

.fortune-share {
  flex: none;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: 500 0.85rem var(--sans);
  cursor: pointer;
  transition: border-color 0.25s, color 0.25s;
}

.fortune-share:hover {
  border-color: var(--gold);
  color: var(--gold-ink);
}

.fortune-share:focus-visible {
  outline: 2px solid var(--gold-ink);
  outline-offset: 2px;
}

.fortune-share.is-copied {
  border-color: var(--gold);
  color: var(--gold-ink);
}

.pill.dl {
  display: inline-flex;
  align-items: center;
  color: var(--text);
  text-decoration: none;
}

/* ---------- larger screens: scene left, luck right ---------- */

.side {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

@media (min-width: 900px) and (min-height: 560px) {
  body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    /* header, cat row, hint row: both columns top-aligned so the side column meets the cat's top */
    grid-template-rows: auto auto auto;
    column-gap: 64px;
    justify-items: center;
    align-items: start;
    max-width: 1080px;
    margin: 0 auto;
    padding: 0 40px 40px;
  }

  .top {
    grid-column: 1 / -1;
    max-width: none;
    padding: 24px 2px 22px;
  }

  .stage {
    grid-column: 1;
    grid-row: 2;
    justify-self: end;
    width: min(42vw, calc((100vh - 140px) / 1.1), 480px);
  }

  .side {
    grid-column: 2;
    grid-row: 2;
    justify-self: start;
    align-self: center; /* one composed column, centred on the cat scene */
    align-items: flex-start;
    max-width: 400px;
  }

  .foot {
    margin-top: 26px; /* same rhythm as the cards above, no dead gap */
  }

  .hint {
    grid-column: 1;
    grid-row: 3;
    justify-self: end;
    align-self: start;
    width: min(42vw, calc((100vh - 140px) / 1.1), 480px);
    margin: -16px 0 0; /* tuck under the cat's feet: the grid gap alone left the hint floating */
    text-align: center;
    font-size: 1.2rem;
  }

  .fortune {
    order: 0;
    margin-top: 10px;
  }

  .foot,
  .actions {
    text-align: left;
    justify-content: flex-start;
  }

  .actions {
    flex-wrap: nowrap;
    gap: 6px;
  }

  .actions .pill {
    padding: 0 13px;
    white-space: nowrap;
  }
}

/* ---------- widget mode (?widget): only the cat ---------- */

html:has(body.widget) {
  background: transparent;
}

body.widget {
  background: transparent;
  padding: 0;
  justify-content: center;
}

body.widget .top,
body.widget .hint,
body.widget .stats,
body.widget .fortune,
body.widget .foot,
body.widget .scene,
body.widget .ground {
  display: none;
}

body.widget .stage {
  width: min(96vw, 96vh);
}

@media (prefers-reduced-motion: reduce) {
  .lantern,
  .scene .gate-halo {
    animation: none;
  }
  .float,
  .coin {
    animation-duration: 0.01ms;
  }
}
