/* ===== Design tokens ===== */
:root {
  --paper: #fffdf8;
  --cream: #f6ecd9;
  --cream-deep: #efe1c6;
  --ink: #3b2f26;
  --ink-soft: #6f6052;
  --line: #e4d6bd;

  --c-team: #e8794a;     --c-team-bg: #fdeadf;
  --c-move: #4aa873;     --c-move-bg: #e2f3e8;
  --c-trust: #4a86c4;    --c-trust-bg: #e2eef9;
  --c-talk: #d8a32e;     --c-talk-bg: #fbf0d4;
  --c-feel: #d4618f;     --c-feel-bg: #fbe5ee;

  --shadow: 0 18px 40px -22px rgba(70,50,30,.55);
  --radius: 22px;
  --font-display: "Fredoka", "Segoe UI Rounded", ui-rounded, system-ui, sans-serif;
  --font-body: "Nunito", ui-rounded, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 15% -10%, #fff7e9 0%, transparent 60%),
    radial-gradient(1000px 700px at 100% 0%, #fdeadf 0%, transparent 55%),
    var(--cream);
  background-attachment: fixed;
  line-height: 1.5;
}
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  opacity: .5;
  background-image: radial-gradient(rgba(120,90,50,.05) 1px, transparent 1.4px);
  background-size: 7px 7px;
  z-index: 0;
}

.wrap { position: relative; z-index: 1; max-width: 1180px; margin: 0 auto; padding: 0 22px 90px; }

/* ===== Header ===== */
header.top { text-align: center; padding: 54px 16px 18px; }
.kicker {
  display: inline-block;
  font-family: var(--font-display); font-weight: 600;
  letter-spacing: .18em; text-transform: uppercase; font-size: .72rem;
  color: var(--c-team); background: var(--c-team-bg);
  padding: 6px 14px; border-radius: 999px;
}
header.top h1 {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(2.1rem, 5.2vw, 3.4rem); line-height: 1.05;
  margin: 16px 0 8px; color: var(--ink);
}
header.top h1 .squiggle { color: var(--c-move); }
header.top p { max-width: 560px; margin: 0 auto; color: var(--ink-soft); font-size: 1.05rem; }

/* ===== Toolbar ===== */
.toolbar {
  position: sticky; top: 0; z-index: 20;
  margin: 22px 0 30px; padding: 12px;
  background: rgba(255,253,248,.82); backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 8px 24px -18px rgba(70,50,30,.5);
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center;
}
.filters { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  font-family: var(--font-display); font-weight: 500; font-size: .9rem;
  border: 1.5px solid var(--line); background: var(--paper); color: var(--ink-soft);
  padding: 7px 14px; border-radius: 999px; cursor: pointer;
  transition: transform .12s ease, background .15s, color .15s, border-color .15s;
}
.chip:hover { transform: translateY(-2px); }
.chip[aria-pressed="true"] { color: #fff; border-color: transparent; background: var(--ink); }
.chip .dot { display:inline-block; width:9px; height:9px; border-radius:50%; margin-right:6px; vertical-align: middle; }

.spacer { flex: 1 1 12px; min-width: 0; }

.btn {
  font-family: var(--font-display); font-weight: 600; font-size: .95rem;
  border: none; cursor: pointer; padding: 10px 18px; border-radius: 999px;
  transition: transform .12s ease, filter .15s, background .15s;
  display: inline-flex; align-items: center; gap: 8px;
}
.btn:hover { transform: translateY(-2px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-print { background: var(--c-team); color: #fff; box-shadow: 0 10px 22px -12px var(--c-team); }
.btn-gen { background: var(--c-trust); color: #fff; box-shadow: 0 10px 22px -12px var(--c-trust); }
.btn-ghost { background: var(--paper); color: var(--ink); border: 1.5px solid var(--line); }
.btn-print:hover, .btn-gen:hover { filter: brightness(1.04); }

.count-note { width: 100%; text-align:center; color: var(--ink-soft); font-size: .85rem; }

.auth-area { display: flex; align-items: center; gap: 8px; }
.auth-user {
  font-size: .82rem; color: var(--ink-soft); max-width: 180px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: var(--cream); border: 1px solid var(--line); padding: 6px 12px; border-radius: 999px;
}
.login-status { font-size: .9rem; color: #2e567f; background: var(--c-trust-bg); border: 1px solid #bcd6ef; padding: 10px 12px; border-radius: 12px; margin: 0 0 4px; }
.login-dev { font-size: .78rem; word-break: break-all; background: var(--c-talk-bg); border: 1px dashed #e0c067; padding: 8px 10px; border-radius: 10px; }

/* ===== Banner ===== */
.banner {
  margin: 0 0 22px; padding: 14px 18px; border-radius: 14px;
  font-size: .95rem; display: none; align-items: center; gap: 10px;
}
.banner.show { display: flex; }
.banner.info { background: var(--c-trust-bg); color: #2e567f; border: 1px solid #bcd6ef; }
.banner.warn { background: var(--c-talk-bg); color: #7a5b13; border: 1px solid #ecd79a; }
.banner.error { background: var(--c-team-bg); color: #9a3d1c; border: 1px solid #f0c2ab; }
.banner button { margin-left: auto; background: none; border: none; font-size: 1.1rem; cursor: pointer; color: inherit; opacity: .7; }

/* ===== Card grid ===== */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 28px; }
.empty { text-align: center; color: var(--ink-soft); padding: 60px 20px; font-size: 1.05rem; grid-column: 1 / -1; }

.card { perspective: 1600px; }
.card-inner {
  position: relative; width: 100%; height: 470px;
  transition: transform .65s cubic-bezier(.34,1.2,.4,1); transform-style: preserve-3d;
}
.card.flipped .card-inner { transform: rotateY(180deg); }

.face {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: var(--radius); background: var(--paper);
  border: 1px solid var(--line); box-shadow: var(--shadow);
  overflow: hidden; display: flex; flex-direction: column;
}
.face-back { transform: rotateY(180deg); }
.face .ribbon { height: 9px; flex: 0 0 9px; }
.face-pad { padding: 20px 22px; display:flex; flex-direction:column; height:100%; }

.meta-row { display:flex; align-items:center; gap:8px; flex-wrap:wrap; margin-bottom: 12px; }
.tag {
  font-family: var(--font-display); font-weight: 600; font-size: .7rem;
  letter-spacing: .06em; text-transform: uppercase; padding: 4px 10px; border-radius: 999px;
}
.pill {
  font-size: .76rem; color: var(--ink-soft); background: var(--cream);
  border: 1px solid var(--line); padding: 3px 9px; border-radius: 999px;
  display:inline-flex; align-items:center; gap:4px;
}
.pill.spark { background: var(--c-trust-bg); border-color:#cfe1f4; color:#34618f; }

.emoji-badge {
  width: 96px; height: 96px; border-radius: 26px; display:grid; place-items:center;
  font-size: 54px; margin: 2px 0 14px; transform: rotate(-4deg);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.6);
}
.card-title { font-family: var(--font-display); font-weight: 700; font-size: 1.5rem; line-height: 1.1; margin: 0 0 10px; }
.story { color: var(--ink); font-size: .98rem; }
.problem {
  margin-top: auto; font-weight: 700; font-style: italic; color: var(--ink);
  background: var(--cream); border-left: 4px solid currentColor;
  padding: 10px 12px; border-radius: 0 12px 12px 0; font-size: .95rem;
}
.flip-hint {
  position:absolute; bottom: 12px; right: 16px; font-size: .75rem; color: var(--ink-soft);
  font-family: var(--font-display); font-weight: 500; display:flex; align-items:center; gap:5px; opacity:.8;
}

.back-title { font-family: var(--font-display); font-weight:700; font-size: 1.15rem; margin: 0 0 4px; }
.section-label {
  font-family: var(--font-display); font-weight: 600; font-size: .72rem;
  letter-spacing: .1em; text-transform: uppercase; color: var(--ink-soft);
  margin: 14px 0 6px; display:flex; align-items:center; gap:6px;
}
ol.steps { margin: 0; padding-left: 0; list-style: none; counter-reset: s; }
ol.steps li { counter-increment: s; position: relative; padding: 4px 0 4px 30px; font-size: .92rem; }
ol.steps li::before {
  content: counter(s); position:absolute; left:0; top: 3px; width: 21px; height: 21px;
  background: currentColor; color:#fff; border-radius: 50%;
  font-family: var(--font-display); font-weight:600; font-size:.72rem; display:grid; place-items:center;
}
ul.mats { margin: 0; padding-left: 18px; font-size: .92rem; }
ul.mats li { margin: 2px 0; }
.back-scroll { overflow:auto; flex:1; }
.back-scroll::-webkit-scrollbar { width: 7px; }
.back-scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; }

.card-controls { display:flex; gap:8px; margin-top: 12px; align-items:center; flex-wrap: wrap; }
.mini-btn {
  font-family: var(--font-display); font-weight:600; font-size:.8rem;
  border:1.5px solid var(--line); background: var(--paper); color: var(--ink-soft);
  border-radius: 999px; padding: 6px 12px; cursor:pointer;
}
.mini-btn.danger { color: #b8431f; border-color: #f0c2ab; }
.mini-btn.danger:hover { background: var(--c-team-bg); }
.mini-btn.save { color: #fff; background: var(--c-move); border-color: transparent; }
.mini-btn.save:hover { filter: brightness(1.05); }

/* Draft cards (generated but not yet saved) */
.pill.draft { background: var(--c-talk-bg); border-color:#ecd79a; color:#7a5b13; }
.card.is-draft .face { border: 2px dashed var(--c-talk); }

/* Bar shown while unsaved drafts exist */
.draftbar {
  margin: 0 0 22px; padding: 12px 18px; border-radius: 14px;
  background: var(--c-talk-bg); border: 1px dashed #e0c067; color: #7a5b13;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  font-size: .95rem; font-weight: 600;
}
.draftbar-actions { margin-left: auto; display: flex; gap: 8px; }

/* Draft decision buttons on the front (story) face */
.draft-actions { margin-top: 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.draft-hint { font-size: .72rem; color: var(--ink-soft); font-family: var(--font-display); font-weight: 500; }
.select-box { display:flex; align-items:center; gap:6px; font-size:.82rem; color: var(--ink-soft); cursor:pointer; user-select:none; }
.select-box input { width:16px; height:16px; accent-color: var(--c-team); }

/* ===== Dialog ===== */
dialog {
  border: none; border-radius: 22px; padding: 0; max-width: 460px; width: calc(100% - 36px);
  box-shadow: 0 30px 70px -25px rgba(70,50,30,.7); color: var(--ink);
}
dialog::backdrop { background: rgba(59,47,38,.45); backdrop-filter: blur(3px); }
.dlg-pad { padding: 26px 26px 22px; }
.dlg-pad h2 { font-family: var(--font-display); font-weight: 700; margin: 0 0 4px; font-size: 1.45rem; }
.dlg-pad p.sub { margin: 0 0 18px; color: var(--ink-soft); font-size: .92rem; }
.field { margin-bottom: 14px; }
.field label { display:block; font-family: var(--font-display); font-weight: 600; font-size: .82rem; margin-bottom: 6px; }
.field select, .field input {
  width: 100%; font-family: var(--font-body); font-size: .95rem;
  padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink);
}
.dlg-actions { display:flex; gap:10px; justify-content:flex-end; margin-top: 20px; }
.gen-status { font-size: .85rem; color: var(--ink-soft); margin-right: auto; align-self: center; display:flex; align-items:center; gap:6px; }

.spin { width: 15px; height: 15px; border: 2.5px solid rgba(74,134,196,.35); border-top-color: var(--c-trust); border-radius:50%; display:inline-block; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

footer.foot { text-align:center; color: var(--ink-soft); font-size:.85rem; margin-top: 54px; }
footer.foot a { color: var(--c-team); }

/* ===== PRINT ===== */
#print-area { display: none; }

@media print {
  @page { size: A4 portrait; margin: 0; }
  body { background: #fff; }
  body::before { display:none; }
  .wrap, header.top, .toolbar, footer.foot, .banner, dialog { display: none !important; }
  #print-area { display: block !important; }

  .sheet { width: 210mm; height: 297mm; page-break-after: always; display: flex; flex-direction: column; position: relative; }
  .sheet:last-child { page-break-after: auto; }
  .half { height: 148.5mm; padding: 13mm 14mm; display: flex; flex-direction: column; overflow: hidden; }
  .half-back { transform: rotate(180deg); }
  .fold { position: absolute; top: 148.5mm; left: 0; right: 0; border-top: 1.4px dashed #b9a888; text-align: center; }
  .fold span { position: relative; top: -9px; background: #fff; padding: 0 10px; font-family: var(--font-display); font-size: 8pt; color: #b9a888; letter-spacing: .1em; }

  .p-ribbon { height: 6mm; border-radius: 4px; margin-bottom: 7mm; }
  .p-meta { display:flex; gap:8px; flex-wrap:wrap; margin-bottom: 6mm; }
  .p-tag { font-family: var(--font-display); font-weight:600; font-size:9pt; padding:3px 11px; border-radius:999px; text-transform:uppercase; letter-spacing:.05em; }
  .p-pill { font-size:9pt; border:1px solid #ddd; border-radius:999px; padding:3px 10px; color:#555; }
  .p-emoji { font-size: 60pt; line-height:1; margin-bottom: 4mm; }
  .p-title { font-family: var(--font-display); font-weight:700; font-size: 26pt; line-height:1.05; margin:0 0 5mm; color: var(--ink); }
  .p-story { font-size: 13.5pt; line-height:1.5; color: var(--ink); }
  .p-problem { margin-top:auto; font-weight:700; font-style:italic; font-size:13pt; border-left:4px solid; padding:4mm 5mm; background:#faf4e8; border-radius:0 10px 10px 0; }
  .p-back-title { font-family: var(--font-display); font-weight:700; font-size:17pt; margin:0 0 2mm; }
  .p-label { font-family: var(--font-display); font-weight:600; font-size:10pt; letter-spacing:.08em; text-transform:uppercase; color:#7a6a58; margin:5mm 0 2mm; }
  .p-steps { margin:0; padding-left: 6mm; font-size:12.5pt; line-height:1.45; }
  .p-steps li { margin: 1.5mm 0; }
  .p-mats { margin:0; padding-left:6mm; font-size:12.5pt; line-height:1.4; }
  .p-foot { margin-top:auto; font-size:9pt; color:#9a8b78; font-family:var(--font-display); }
  .face, .card-inner { box-shadow:none !important; }
}
