/* --- Fun widgets: Calculator, Higher or Lower, Daily Quiz (fun-widgets.js) -------------------- */

.fun-body {
  --fun-good: #7cc49a;
  --fun-radius: 14px;
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  container-type: inline-size;
  scrollbar-width: thin;
}
:root[data-theme="light"] .fun-body { --fun-good: #2f8a57; }
.fun-body:focus { outline: none; }
.fun-body:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--fun-radius); }

.fun-help { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.45; }
.fun-help small { font-size: 11px; }

.fun-board { list-style: none; margin: 0; padding: 0; width: min(300px, 100%); font-size: 13px; }
.fun-board li { display: flex; justify-content: space-between; gap: 10px; padding: 4px 10px; border-radius: 8px; }
.fun-board li:nth-child(odd) { background: var(--surface); }
.fun-board li b { font-variant-numeric: tabular-nums; }
.fun-board li.is-you { background: color-mix(in srgb, var(--teal) 28%, transparent); }
.fun-empty { justify-content: center !important; color: var(--muted); background: none !important; }

/* --- Calculator ------------------------------------------------------------------------------- */

.calc { display: flex; flex-direction: column; gap: 10px; }

.calc-screen {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 2px;
  min-height: 74px;
  padding: 10px 14px;
  border-radius: var(--fun-radius);
  background: var(--input-bg);
  border: 1px solid var(--surface-border);
  overflow: hidden;
  text-align: right;
}
.calc:focus-visible .calc-screen { border-color: var(--accent); }
.calc-expr { min-height: 16px; max-width: 100%; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.calc-value {
  max-width: 100%;
  font-size: 32px; /* shrunk to fit by fitValue() in fun-widgets.js */
  font-weight: 600;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  transition: color 0.15s;
}
.calc-value.is-running { color: var(--muted); }
.calc-value.is-error { color: var(--danger); white-space: normal; }
.calc-preview { min-height: 15px; font-size: 13px; color: var(--accent); font-variant-numeric: tabular-nums; }

.calc-keys {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: minmax(34px, 1fr);
  gap: 6px;
}
.calc-key {
  min-width: 0;
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 18px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}
.calc-key:hover { background: color-mix(in srgb, var(--text) 9%, transparent); }
.calc-key:active,
.calc-key.is-pressed { animation: calc-press 0.16s ease-out; }
.calc-fn { color: var(--accent); font-size: 16px; }
.calc-op { background: color-mix(in srgb, var(--teal) 20%, transparent); border-color: color-mix(in srgb, var(--teal) 40%, transparent); color: var(--accent); font-size: 20px; }
.calc-op:hover { background: color-mix(in srgb, var(--teal) 32%, transparent); }
.calc-eq { background: var(--teal); border-color: var(--teal); color: #fff; font-size: 20px; }
.calc-eq:hover { background: var(--teal); filter: brightness(1.1); }
.calc-key:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

@keyframes calc-press {
  0% { transform: scale(1); }
  40% { transform: scale(0.92); }
  100% { transform: scale(1); }
}

/* --- Higher or Lower -------------------------------------------------------------------------- */

.hl-stats { display: flex; align-items: center; gap: 10px; }
.hl-streak {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  font-size: 13px;
}
.hl-streak b { font-variant-numeric: tabular-nums; min-width: 1ch; text-align: center; }
.hl-streak.is-bumped { animation: hl-bump 0.45s ease-out; border-color: var(--fun-good); }

.hl { display: flex; flex-direction: column; gap: 8px; min-height: 200px; }
.hl-cards { flex: 1; display: flex; align-items: stretch; gap: 8px; min-height: 0; }
.hl-cards.is-sliding .hl-card { animation: hl-slide-in 0.42s cubic-bezier(0.2, 0.8, 0.2, 1); }
.hl-cards.is-sliding .hl-b { animation-delay: 0.06s; animation-fill-mode: backwards; }

.hl-card {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 12px;
  border-radius: 16px;
  background: var(--raised);
  border: 1px solid var(--surface-border);
  text-align: center;
  transition: border-color 0.25s, box-shadow 0.25s, background 0.25s;
}
.hl-b { background: linear-gradient(160deg, color-mix(in srgb, var(--teal) 14%, var(--raised)), var(--raised)); }
.hl-card.is-right { border-color: var(--fun-good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--fun-good) 30%, transparent); animation: hl-pop 0.4s ease-out; }
.hl-card.is-wrong { border-color: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 30%, transparent); animation: hl-shake 0.45s ease-in-out; }
.hl-card.is-right .hl-price { color: var(--fun-good); }
.hl-card.is-wrong .hl-price { color: var(--danger); }

.hl-emoji { font-size: 34px; line-height: 1; }
.hl-name { font-size: 14px; font-weight: 500; line-height: 1.3; overflow-wrap: anywhere; }
.hl-price { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); }
.hl-reveal:not([hidden]) { animation: hl-flip 0.35s ease-out; }
.hl-tag { font-size: 11px; color: var(--muted); }
.hl-tag[hidden], .hl-ask[hidden], .hl-reveal[hidden] { display: none; }

.hl-ask { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.hl-ask p { margin: 0; font-size: 12px; color: var(--muted); }
.hl-ask p b { color: var(--text); }
.hl-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.hl-btn {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s;
}
.hl-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.hl-btn:active { transform: translateY(1px); }
.hl-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.hl-higher { background: var(--teal); color: #fff; }
.hl-lower { background: var(--surface); border-color: var(--surface-border); color: var(--text); }

.hl-vs {
  align-self: center;
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--surface-border);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.hl-note { margin: 0; font-size: 11px; color: var(--muted); text-align: center; }

.hl-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 12px;
  box-sizing: border-box;
  border-radius: var(--fun-radius);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(4px);
  text-align: center;
  overflow-y: auto;
  animation: fun-fade 0.25s ease-out;
}
.hl-overlay[hidden] { display: none; }
.hl-overlay > :first-child { margin-top: auto; }
.hl-overlay > :last-child { margin-bottom: auto; }
.hl-overlay h3 { margin: 0; font-size: 18px; }
.hl-overlay[data-mode="over"] h3 { color: var(--text); }
.hl-big-emoji { font-size: 34px; line-height: 1; }
.hl-final { margin: 0; font-size: 40px; font-weight: 700; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; animation: hl-pop 0.5s ease-out; }
.hl-board-title { margin: 6px 0 0; font-size: 11px; font-weight: 500; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }

/* Narrow tile: stack the two cards */
@container (max-width: 330px) {
  .hl-cards { flex-direction: column; }
  .hl-card { flex-direction: row; flex-wrap: wrap; justify-content: center; padding: 10px; gap: 4px 10px; }
  .hl-emoji { font-size: 26px; }
  .hl-name { flex: 1 1 60%; text-align: left; }
  .hl-price { font-size: 20px; }
  .hl-ask { flex-basis: 100%; }
  .hl-vs { width: 24px; height: 24px; font-size: 10px; }
}

@keyframes hl-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); }
  100% { transform: scale(1); }
}
@keyframes hl-pop {
  0% { transform: scale(0.94); }
  60% { transform: scale(1.04); }
  100% { transform: scale(1); }
}
@keyframes hl-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}
@keyframes hl-flip {
  from { transform: rotateX(90deg); opacity: 0; }
  to { transform: rotateX(0); opacity: 1; }
}
@keyframes hl-slide-in {
  from { transform: translateX(24px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes fun-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --- Daily Quiz ------------------------------------------------------------------------------------ */

.quiz { display: flex; flex-direction: column; gap: 10px; padding-right: 2px; }
.quiz-loading, .quiz-error { margin: auto; padding: 20px 0; font-size: 14px; color: var(--muted); text-align: center; }
.quiz-error { color: var(--danger); padding-bottom: 8px; }
.quiz-center { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: auto; }

.quiz-intro {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 14px;
  border-radius: 16px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--teal) 16%, var(--raised)), var(--raised));
  border: 1px solid var(--surface-border);
  text-align: center;
}
.quiz-big-emoji { font-size: 36px; line-height: 1; }
.quiz-lead { margin: 0; font-size: 15px; font-weight: 500; line-height: 1.4; max-width: 380px; }

.quiz-top { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.quiz-dots { display: flex; gap: 4px; }
.quiz-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--surface-border); transition: background 0.2s, transform 0.2s; }
.quiz-dot.is-done { background: var(--teal); }
.quiz-dot.is-now { background: var(--accent); transform: scale(1.3); }
.quiz-count { flex: 1; }
.quiz-clock { font-variant-numeric: tabular-nums; padding: 2px 8px; border-radius: 999px; background: var(--surface); }

.quiz-card { display: flex; flex-direction: column; gap: 10px; animation: quiz-in 0.3s ease-out; }
.quiz-q { margin: 0; font-size: 16px; font-weight: 500; line-height: 1.4; }
.quiz-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 6px; }
.quiz-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--surface-border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.quiz-option:hover { border-color: color-mix(in srgb, var(--accent) 55%, transparent); background: color-mix(in srgb, var(--teal) 10%, transparent); }
.quiz-option:active { transform: scale(0.98); }
.quiz-option:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.quiz-option.is-chosen { border-color: var(--accent); background: color-mix(in srgb, var(--teal) 28%, transparent); }
.quiz-letter {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 8px;
  background: var(--raised);
  border: 1px solid var(--surface-border);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}
.quiz-option.is-chosen .quiz-letter { background: var(--teal); border-color: var(--teal); color: #fff; }
.quiz-nav { display: flex; justify-content: space-between; align-items: center; }

.quiz-score {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 16px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--teal) 18%, var(--raised)), var(--raised));
  border: 1px solid var(--surface-border);
}
.quiz-score.is-fresh { animation: hl-pop 0.5s ease-out; }
.quiz-score-num { font-size: 38px; font-weight: 700; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }
.quiz-score-num span { font-size: 18px; color: var(--muted); font-weight: 500; }
.quiz-cheer { margin: 0 0 2px; font-size: 16px; font-weight: 600; }

.quiz-next { margin: 0; font-size: 12px; color: var(--muted); text-align: center; }
.quiz-next b { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 600; }

.quiz-sub { margin: 4px 0 0; font-size: 11px; font-weight: 500; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }

.quiz-review { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.quiz-review-item { padding: 8px 10px 8px 12px; border-radius: 12px; background: var(--surface); border-left: 3px solid var(--fun-good); }
.quiz-review-item.is-wrong { border-left-color: var(--danger); }
.quiz-review-q { margin: 0; display: flex; gap: 8px; font-size: 13px; font-weight: 500; line-height: 1.35; }
.quiz-mark { flex: none; font-weight: 700; color: var(--fun-good); }
.is-wrong .quiz-mark { color: var(--danger); }
.quiz-review-a { margin: 4px 0 0 20px; display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 12px; }
.quiz-yours { color: var(--danger); text-decoration: line-through; text-decoration-thickness: 1px; }
.quiz-right { color: var(--fun-good); font-weight: 500; }
.quiz-explain { margin: 3px 0 0 20px; font-size: 12px; color: var(--muted); line-height: 1.4; }

.quiz-board { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.quiz-board li { display: grid; grid-template-columns: 26px 1fr auto 56px; align-items: center; gap: 8px; padding: 5px 10px; border-radius: 8px; }
.quiz-board li:nth-child(odd) { background: var(--surface); }
.quiz-board li.is-you { background: color-mix(in srgb, var(--teal) 28%, transparent); }
.quiz-board li.fun-empty { display: flex; }
.quiz-rank { text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.quiz-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quiz-board b { font-variant-numeric: tabular-nums; }
.quiz-board small { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

@keyframes quiz-in {
  from { transform: translateY(6px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .fun-body *, .hl-streak { animation: none !important; transition: none !important; }
}

/* --- Window Stack (stack-game.js) --------------------------------------------------------------- */
.stk { display: flex; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; cursor: pointer; }
.stk-canvas { display: block; flex: 1; width: 100%; height: 100%; min-height: 0; border-radius: var(--fun-radius); touch-action: none; }
