/* BlindRank — "The Deck": paper, ink and a coral accent. */
:root {
  --bg: #EFE8DB;
  --paper: #F8F4EC;
  --surface: #FFFFFF;
  --ink: #1F1B16;
  --muted: #5E564B;
  --line: #B7AB95;
  --filled: #E5DCCB;
  --pile-1: #E5DCCB;
  --pile-2: #D9CFBD;
  --accent: #C2411C;
  --accent-text: #FFFFFF;
  --accent-soft: #FBE7DF;
  --match: #2B59C3;
  --match-soft: #E3EAF8;
  --danger: #B3261E;
  --swap: #8A5A00;
  --swap-soft: #FBEFD6;
  --shadow: #1F1B16;
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15120F;
    --paper: #1E1A16;
    --surface: #27221C;
    --ink: #F3ECE0;
    --muted: #B3A894;
    --line: #5A5247;
    --filled: #332D26;
    --pile-1: #3A332B;
    --pile-2: #2F2923;
    --accent: #F07A52;
    --accent-text: #1A1410;
    --accent-soft: #3B241A;
    --match: #86A8F2;
    --match-soft: #1E2738;
    --danger: #F2867D;
    --swap: #E8B04A;
    --swap-soft: #3A2E18;
    --shadow: #000000;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main {
  max-width: 520px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

h1 { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; margin: 0 0 6px; text-align: center; overflow-wrap: anywhere; }
h2 { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 4px; text-align: center; }
.sub { color: var(--muted); text-align: center; margin: 0 0 22px; }
.hint { color: var(--muted); font-size: 0.92rem; }
.center { text-align: center; }
.optional { color: var(--muted); font-weight: 400; }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0; }

/* ---------- form ---------- */
.field { display: block; border: 0; padding: 0; margin: 0 0 18px; }
.field > span, .field > legend { display: block; font-weight: 600; margin-bottom: 6px; padding: 0; }
.field small { font-weight: 400; }
input[type="text"] {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
}
input[type="text"]:focus { outline: none; border-color: var(--ink); }

.item-inputs { margin: 0; padding: 0; list-style: none; counter-reset: n; display: grid; gap: 8px; }
.item-inputs li { display: flex; align-items: center; gap: 10px; counter-increment: n; }
.item-inputs li::before { content: counter(n); width: 1.6em; text-align: right; color: var(--muted); font-weight: 800; font-variant-numeric: tabular-nums; }

.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; margin: 4px 0 8px; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); }
.check small { color: var(--muted); }

/* ---------- buttons ---------- */
button, .btn {
  font: inherit;
  font-weight: 600;
  border-radius: 14px;
  padding: 10px 18px;
  min-height: 48px;
  border: 2px solid var(--ink);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
button:disabled { cursor: not-allowed; opacity: 0.45; }
.primary {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 800;
  box-shadow: 3px 4px 0 var(--shadow);
}
.primary:active:not(:disabled) { transform: translate(2px, 3px); box-shadow: 1px 1px 0 var(--shadow); }
.primary:disabled { box-shadow: none; }
.big { width: 100%; min-height: 54px; font-size: 1.05rem; }

.result {
  margin-top: 24px;
  padding: 16px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--surface);
}

/* ---------- play ---------- */
.play-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.play-head h1 { font-size: 1.4rem; text-align: left; margin: 0; }
.progress { color: var(--muted); margin: 0; white-space: nowrap; font-size: 0.95rem; }
.intro {
  text-align: center;
  background: var(--accent-soft);
  border-radius: 12px;
  padding: 10px 14px;
  margin: 0 0 12px;
  font-size: 0.95rem;
}

.pile { position: relative; height: 232px; margin: 4px 0 18px; }
.pile-back, .top-card { position: absolute; border-radius: 22px; }
.pile-back.b2 { left: 12%; right: 5%; top: 24px; height: 200px; background: var(--pile-2); transform: rotate(5deg); }
.pile-back.b1 { left: 5%; right: 11%; top: 16px; height: 200px; background: var(--pile-1); transform: rotate(-4deg); }
.top-card {
  left: 7%; right: 7%; top: 6px; height: 208px;
  background: var(--surface);
  border: 2px solid var(--ink);
  box-shadow: 6px 8px 0 var(--shadow);
  transform: rotate(-1.5deg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}
.top-card.dragging { cursor: grabbing; box-shadow: 10px 14px 0 var(--shadow); z-index: 10; transition: none; }
.top-card.returning { transition: transform 0.25s ease; }
.top-card.deal { animation: deal 0.35s cubic-bezier(.2, .8, .3, 1.2); }
@keyframes deal {
  from { transform: translateY(-40px) rotate(-8deg); opacity: 0; }
  to { transform: rotate(-1.5deg); opacity: 1; }
}
.card-num { margin: 0; font-size: 0.8rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.card-item { margin: 0; font-size: clamp(1.8rem, 9vw, 2.75rem); line-height: 1.05; font-weight: 800; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.card-hint { margin: 0; font-size: 0.9rem; color: var(--muted); }

.feel { margin: 0 0 14px; text-align: center; }
.feel p { margin: 0 0 6px; font-weight: 600; font-size: 0.95rem; }
.faces { display: flex; justify-content: center; gap: 8px; }
.faces button {
  font-size: 1.6rem;
  padding: 0;
  width: 48px;
  height: 48px;
  min-height: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  background: transparent;
  filter: grayscale(0.7);
  opacity: 0.7;
}
.faces button:hover { opacity: 1; filter: none; }
.faces button.selected { border-color: var(--accent); background: var(--accent-soft); filter: none; opacity: 1; }

.pockets { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-flow: column; gap: 8px; }
.pocket {
  justify-content: flex-start;
  gap: 10px;
  min-height: 48px;
  padding: 0 12px;
  border: 2px dashed var(--line);
  background: transparent;
  text-align: left;
  font-weight: 600;
}
.pocket .p-rank { width: 1.4em; font-size: 1.1rem; font-weight: 800; flex: none; }
.pocket .p-name { font-size: 0.92rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pocket.used { border-style: solid; border-color: var(--filled); background: var(--filled); color: var(--muted); opacity: 1; cursor: default; }
.pocket.selected { border-style: solid; border-color: var(--accent); background: var(--surface); color: var(--accent); }
.pocket.drop-target { border-style: solid; border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.pockets.swapping .pocket.used { color: var(--swap); background: var(--swap-soft); border-color: var(--swap); cursor: pointer; }
.pockets.swapping .pocket.swap-first { background: var(--swap); color: var(--paper); }
.pockets.swapping .pocket:not(.used) { opacity: 0.3; }
.pocket.flash { animation: flash 0.9s ease; }
@keyframes flash { from { background: var(--swap-soft); } }

.swap-row { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.swap { border-color: var(--swap); color: var(--swap); }
.swap.active { background: var(--swap); color: var(--paper); }

.actions { display: flex; gap: 10px; margin-top: 16px; }
.actions #p-undo { flex: 1; }
.actions #p-next { flex: 2; }

/* ---------- results ---------- */
.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.board li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--surface);
  border: 2px solid var(--filled);
  min-height: 46px;
}
.board .rank { font-weight: 800; width: 1.6em; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.board .name { flex: 1; overflow-wrap: anywhere; font-weight: 600; }
.board .face { font-size: 1.3rem; }

.owner { margin: 0 0 20px; }
.owner-lead { margin: 0 0 10px; font-weight: 800; text-align: center; }
.link-row { display: flex; gap: 8px; }
.link-row input { flex: 1; min-width: 0; }
.owner .hint { text-align: center; margin: 10px 0 0; }

.compare { margin: 0 0 8px; }
.score { text-align: center; color: var(--muted); margin: 0 0 16px; }
.score strong { color: var(--ink); }
.cross-head { display: flex; justify-content: space-between; font-size: 0.8rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.cross { display: grid; grid-template-columns: minmax(0, 1fr) 72px minmax(0, 1fr); }
.cross-lines { width: 72px; display: block; overflow: visible; }
.cross-col { list-style: none; margin: 0; padding: 0; }
.cross-col li { height: 44px; display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 0.95rem; min-width: 0; }
.cross-col .c-rank { color: var(--muted); font-weight: 800; width: 1.4em; flex: none; font-variant-numeric: tabular-nums; }
.cross-col .c-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cross-col.right li { justify-content: flex-end; text-align: right; }
.cross-col.right .c-rank { text-align: right; }
.cross-col li.match .c-name { color: var(--match); }
.cross-col li.far .c-name { color: var(--accent); }
.cross-lines path { fill: none; stroke-linecap: round; stroke: var(--line); stroke-width: 3; }
.cross-lines path.match { stroke: var(--match); }
.cross-lines path.far { stroke: var(--accent); stroke-width: 4; }

.split {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  align-items: baseline;
  margin: 16px 0 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 2px solid var(--ink);
}
.split .split-label { font-size: 0.8rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); }

.pending, .saving {
  text-align: center;
  padding: 12px 14px;
  border: 2px dashed var(--line);
  border-radius: 14px;
  color: var(--muted);
}
.saving.error { color: var(--danger); border-color: var(--danger); }
.saving button { margin-top: 8px; }

.share { margin-top: 24px; }
.preview {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 15px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--paper);
  border-radius: 10px;
  padding: 12px;
  margin: 12px 0 14px;
}
.footer-links { text-align: center; margin-top: 24px; }
.footer-links a { color: var(--accent); font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  .top-card.deal, .pocket.flash { animation: none; }
  .top-card.returning { transition: none; }
}
