/* Reimagine: a physical-looking Imagine card on a cool tabletop. */

:root {
  --ground: #dde7e6;
  --ink: #1b2130;
  --muted: #53646a;
  --line: #b4c4c5;
  --raised: #f4f8f8;
  --accent: #c4214d;
  --accent-ink: #ffffff;
  --focus: #c4214d;
  --backdrop: rgb(15 25 28 / 0.45);
  --shadow: 0 1px 2px rgb(20 40 45 / 0.14), 0 14px 34px -10px rgb(20 40 45 / 0.34);

  /* The card itself stays a light, printed object in both themes. */
  --card-rim: #fbfdfd;
  --card-ink: #1b2130;
  --teal: #10807a;
  --navy: #1e2432;
  --crimson: #c4214d;
  --band: #c9d7d9;
  --paper: #f7fafa;
  --word: #0c6c67;

  --font: "Jost", "Futura", "Century Gothic", "Avenir Next", system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #0f1618;
    --ink: #e1eaea;
    --muted: #93a6a9;
    --line: #2d3c40;
    --raised: #172124;
    --accent: #d42a57;
    --focus: #ff6f94;
    --backdrop: rgb(0 0 0 / 0.6);
    --shadow: 0 0 0 1px rgb(255 255 255 / 0.1), 0 1px 2px rgb(0 0 0 / 0.5), 0 18px 40px -12px rgb(0 0 0 / 0.75);
    --card-rim: #eef4f4;
    --band: #bccbcd;
    --paper: #edf3f3;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --ground: #0f1618;
  --ink: #e1eaea;
  --muted: #93a6a9;
  --line: #2d3c40;
  --raised: #172124;
  --accent: #d42a57;
  --focus: #ff6f94;
  --backdrop: rgb(0 0 0 / 0.6);
  --shadow: 0 0 0 1px rgb(255 255 255 / 0.1), 0 1px 2px rgb(0 0 0 / 0.5), 0 18px 40px -12px rgb(0 0 0 / 0.75);
  --card-rim: #eef4f4;
  --band: #bccbcd;
  --paper: #edf3f3;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding-inline: 16px;
  padding-block: 0 24px;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
}

button { font: inherit; color: inherit; }
button:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.app {
  max-width: 1040px;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-block: 18px 0;
}

.brand { min-width: 0; }
.wordmark {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1;
}
.wordmark span { color: var(--accent); }
.tagline {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.3;
}

.ghost {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: transparent;
  font-weight: 500;
  cursor: pointer;
}
.ghost:hover { background: var(--raised); }
.count {
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

main {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- card bar ---------- */

.cardbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
}
.cardno {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.cardno b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

.sidehint {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}
#sideName { color: var(--ink); font-weight: 500; }
.dots { display: inline-flex; gap: 5px; }
.dots i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1.5px solid var(--muted);
}
.dots i:first-child, .flipped-b .dots i:last-child { background: var(--ink); border-color: var(--ink); }
.flipped-b .dots i:first-child { background: transparent; border-color: var(--muted); }

/* ---------- the card ---------- */

.stage {
  perspective: 1600px;
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
  cursor: grab;
}
.stage.dragging { cursor: grabbing; }

.flipper {
  display: grid;
  max-width: 460px;
  margin-inline: auto;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.3, 0.7, 0.2, 1);
}

.face {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  min-width: 0;
}
.face-b { transform: rotateY(180deg); }

.face-label {
  display: none;
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rows {
  flex: 1;
  list-style: none;
  margin: 0;
  padding: 5px 5px 5px 0;
  background: var(--card-rim);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  color: var(--card-ink);
}

.row {
  display: grid;
  grid-template-columns: 3.2rem 1fr;
  grid-template-rows: auto 1fr;
  border-top: 2px solid var(--crimson);
}
.row:first-child { border-top: 0; }

.num {
  grid-row: 1 / span 2;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--teal);
  color: #f4f8f8;
  font-size: 1.85rem;
  font-weight: 500;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.row:nth-child(even) .num { background: var(--navy); }
.row:first-child .num { border-top-left-radius: 11px; }
.row:last-child .num { border-bottom-left-radius: 11px; }

.cat {
  padding: 7px 12px 5px;
  background: var(--band);
  background: linear-gradient(var(--band) 72%, color-mix(in srgb, var(--band) 55%, var(--paper)) 72%);
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  line-height: 1.2;
  text-transform: uppercase;
}

.word {
  padding: 6px 12px 8px;
  background: var(--paper);
  color: var(--word);
  font-size: 1.2rem;
  line-height: 1.2;
  overflow-wrap: break-word;
  text-wrap: balance;
}

.deal .rows { animation: deal 0.32s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes deal {
  from { transform: translateY(14px) rotate(-0.8deg); }
  to { transform: none; }
}

/* Wide screens: lay both sides out next to each other. */
@media (min-width: 860px) {
  .sidehint { display: none; }
  .stage { cursor: auto; }
  .flipper {
    grid-template-columns: 1fr 1fr;
    gap: 28px;
    max-width: none;
    transform: none !important;
  }
  .face, .face-b { grid-area: auto; transform: none; }
  .face-label { display: block; }
  .word { font-size: 1.25rem; }
}

/* ---------- actions ---------- */

.actions {
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  gap: 10px;
  max-width: 460px;
  width: 100%;
  margin-inline: auto;
}

.primary, .secondary {
  min-height: 56px;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 600;
  touch-action: manipulation;
}
.primary {
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1.1rem;
  letter-spacing: 0.01em;
  box-shadow: 0 6px 18px -8px color-mix(in srgb, var(--accent) 80%, transparent);
}
.primary:hover { filter: brightness(1.06); }
.primary:active { transform: translateY(1px); }
.primary:disabled { opacity: 0.45; cursor: not-allowed; }

.secondary {
  border: 1.5px solid var(--line);
  background: var(--raised);
  color: var(--ink);
}
.secondary:hover { border-color: var(--muted); }
.secondary:disabled { opacity: 0.4; cursor: default; }

.square { display: grid; place-items: center; padding: 0; }
.square svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

.small { min-height: 38px; padding: 0 14px; font-size: 0.9rem; border-radius: 999px; }

.status {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

@media (min-width: 860px) {
  .actions { max-width: 560px; }
}

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

.foot {
  max-width: 560px;
  width: 100%;
  margin-inline: auto;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}
.foot p { margin: 0 0 8px; }

.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.link.confirm { color: var(--accent); }

/* ---------- categories sheet ---------- */

dialog {
  width: min(600px, calc(100% - 32px));
  max-height: min(86vh, 900px);
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--ground);
  color: var(--ink);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: var(--backdrop); }

.sheet { display: flex; flex-direction: column; max-height: inherit; }

.sheet-head { padding: 20px 20px 12px; border-bottom: 1.5px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 1.35rem; font-weight: 600; text-wrap: balance; }
.sheet-head p { margin: 4px 0 12px; color: var(--muted); font-size: 0.92rem; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; }

.groups {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px 8px;
}
.groups fieldset { margin: 0 0 14px; padding: 0; border: 0; min-width: 0; }
.groups legend {
  padding: 0;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip { position: relative; display: inline-flex; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--raised);
  font-size: 0.92rem;
  font-weight: 500;
}
.chip small { color: var(--muted); font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.chip input:checked + span { border-color: var(--teal); background: var(--teal); color: #f4f8f8; }
.chip input:checked + span small { color: #cfe7e5; }
.chip input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.sheet-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 12px 20px 16px;
  border-top: 1.5px solid var(--line);
}
.sheet-foot .primary { min-height: 48px; padding: 0 28px; }
.hint { flex: 1; margin: 0; color: var(--muted); font-size: 0.88rem; }

.noscript { margin: 24px auto; max-width: 460px; text-align: center; }

@media (max-width: 380px) {
  .tagline { font-size: 0.82rem; }
  .ghost { padding: 0 12px; }
  .row { grid-template-columns: 2.8rem 1fr; }
  .num { font-size: 1.6rem; }
  .cat { font-size: 0.82rem; padding-inline: 10px; }
  .word { font-size: 1.08rem; padding-inline: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .flipper { transition: none; }
  .deal .rows { animation: none; }
}
