:root {
  --paper: #fbf3e2;
  --paper-2: #f4e6c8;
  --paper-3: #ead6ad;
  --ink: #23283f;
  --ink-soft: #545a73;
  --barn: #b4462f;
  --barn-dark: #8e3322;
  --wheat: #e2a93b;
  --wheat-soft: #f5d78e;
  --sage: #6f8f6a;
  --sage-soft: #cddcc3;
  --sky: #3f7fb5;
  --plum: #7a4a8c;
  --gold: #c8922a;
  --line: rgba(35, 40, 63, 0.14);
  --shadow: 0 2px 0 rgba(35, 40, 63, 0.12), 0 10px 24px -12px rgba(35, 40, 63, 0.35);
  --radius: 18px;
  --display: 'Fraunces', Georgia, serif;
  --body: 'Nunito', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  background-image:
    radial-gradient(circle at 12% 8%, rgba(226, 169, 59, 0.18), transparent 38%),
    radial-gradient(circle at 92% 30%, rgba(111, 143, 106, 0.14), transparent 40%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.5;
  min-height: 100vh;
}
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
button { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3 { font-family: var(--display); font-variation-settings: 'SOFT' 100; line-height: 1.1; margin: 0; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px clamp(16px, 4vw, 40px);
  background: rgba(251, 243, 226, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 2px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-family: var(--display); font-weight: 800; font-size: 24px; font-variation-settings: 'SOFT' 100; }
.brand-mark { width: 34px; height: 34px; flex: none; }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tabs a { text-decoration: none; font-weight: 800; padding: 8px 14px; border-radius: 999px; color: var(--ink-soft); }
.tabs a:hover { background: var(--paper-2); color: var(--ink); }
.tabs a.on { background: var(--ink); color: var(--paper); }
.wallet { display: flex; align-items: center; gap: 6px; background: #fff8ea; border: 2px solid var(--line); border-radius: 999px; padding: 4px 12px 4px 8px; font-weight: 900; }
.ink-drop { width: 16px; height: 21px; flex: none; }
.wallet.bump { animation: bump .5s ease; }
@keyframes bump { 40% { transform: scale(1.18); } }

main { max-width: 1100px; margin: 0 auto; padding: 28px clamp(16px, 4vw, 40px) 80px; outline: none; }

.credit { text-align: center; font-size: 14px; font-weight: 700; color: var(--ink-soft); padding: 0 16px 32px; margin-top: -48px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 14px; padding: 12px 20px; cursor: pointer;
  font-weight: 900; font-size: 17px; text-decoration: none;
  background: var(--barn); color: #fff;
  box-shadow: inset 0 -4px 0 var(--barn-dark);
  transition: transform .08s ease, filter .15s ease;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(2px); box-shadow: inset 0 -2px 0 var(--barn-dark); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 2px var(--line); }
.btn.gold { background: var(--wheat); color: var(--ink); box-shadow: inset 0 -4px 0 #b9842a; }
.btn.small { padding: 8px 14px; font-size: 15px; border-radius: 12px; }
.btn svg { width: 22px; height: 22px; }

/* Panels */
.panel { background: #fffaf0; border: 2px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.eyebrow { font-weight: 900; text-transform: uppercase; letter-spacing: .08em; font-size: 13px; color: var(--barn); }
.muted { color: var(--ink-soft); }
.note { font-size: 14px; color: var(--ink-soft); }

/* Home */
.hero { display: grid; grid-template-columns: 1.2fr 1fr; gap: 28px; align-items: center; margin-bottom: 36px; }
.hero h1 { font-size: clamp(36px, 6vw, 60px); font-weight: 800; }
.hero h1 em { font-style: normal; color: var(--barn); }
.hero p { font-size: 19px; max-width: 34ch; }
.loop { display: grid; gap: 10px; }
.loop-step { display: flex; gap: 14px; align-items: center; background: #fffaf0; border: 2px solid var(--line); border-radius: 16px; padding: 12px 16px; font-weight: 800; }
.loop-step .num { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--ink); color: var(--paper); font-family: var(--display); }
.loop-step:nth-child(2) .num { background: var(--sky); }
.loop-step:nth-child(3) .num { background: var(--plum); }
.loop-step:nth-child(4) .num { background: var(--wheat); color: var(--ink); }

.shelf-title { display: flex; align-items: baseline; justify-content: space-between; margin: 8px 0 16px; }
.shelf-title h2 { font-size: 28px; }
.shelf { display: grid; gap: 18px; }
.bookrow { display: grid; grid-template-columns: 150px 1fr; gap: 24px; align-items: center; text-decoration: none; transition: transform .12s ease; }
.bookrow:hover { transform: translateY(-2px); }
.booktitle { font-size: 30px; }
.cardshead { font-size: 24px; margin: 34px 0 14px; }
.cardshead:first-of-type { margin-top: 8px; }
.cover {
  aspect-ratio: 2 / 3; border-radius: 6px 14px 14px 6px; position: relative; overflow: hidden;
  background: linear-gradient(170deg, var(--from, #e9b85a) 0%, var(--to, #9c4a2a) 100%);
  box-shadow: inset 8px 0 0 rgba(0,0,0,.18), var(--shadow);
  color: #fff8e8; padding: 16px 14px 14px 22px; display: flex; flex-direction: column; justify-content: space-between;
}
.cover::before { content: ''; position: absolute; left: -10%; right: -10%; bottom: 18%; height: 30%; background: var(--land, #4f6b4b); border-radius: 50% 50% 0 0; opacity: .55; }
.cover::after { content: ''; position: absolute; left: -10%; right: -10%; bottom: 0; height: 24%; background: var(--land, #4f6b4b); border-radius: 60% 40% 0 0; }
.cover .t { font-family: var(--display); font-weight: 800; font-size: 24px; line-height: 1.05; position: relative; z-index: 1; font-variation-settings: 'SOFT' 100; }
.cover .a { font-weight: 800; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; position: relative; z-index: 1; }
.cover .sun { position: absolute; width: 46px; height: 46px; border-radius: 50%; background: #fff1c4; right: 18px; top: 44%; opacity: .9; }
.meter { height: 12px; background: var(--paper-2); border-radius: 999px; overflow: hidden; border: 2px solid var(--line); }
.meter > span { display: block; height: 100%; background: linear-gradient(90deg, var(--sage), #93b18b); border-radius: 999px; transition: width .6s ease; }
.tags { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 14px; }
.tag { font-size: 13px; font-weight: 800; padding: 3px 10px; border-radius: 999px; background: var(--paper-2); }

/* Book trail */
.bookhead { display: grid; grid-template-columns: 140px 1fr; gap: 24px; align-items: center; margin-bottom: 28px; }
.bookhead h1 { font-size: clamp(32px, 5vw, 46px); }
.trail { position: relative; display: grid; gap: 18px; }
.stop { display: grid; grid-template-columns: 64px 1fr auto; gap: 18px; align-items: center; padding: 16px 18px; border-radius: var(--radius); background: #fffaf0; border: 2px solid var(--line); box-shadow: var(--shadow); position: relative; }
.stop:not(:last-child)::after { content: ''; position: absolute; left: 49px; top: 100%; height: 18px; border-left: 4px dotted var(--paper-3); }
.stop .badge { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-family: var(--display); font-weight: 800; font-size: 28px; background: var(--paper-2); color: var(--ink-soft); border: 3px solid var(--line); }
.stop.open { border-color: var(--barn); }
.stop.open .badge { background: var(--barn); color: #fff; border-color: var(--barn-dark); }
.stop.passed .badge { background: var(--sage); color: #fff; border-color: #567253; }
.stop.locked { opacity: .62; box-shadow: none; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(180, 70, 47, .15); } }
.stop h3 { font-size: 22px; }
.stop .hint { margin: 2px 0 0; color: var(--ink-soft); }
.stars { color: var(--wheat); letter-spacing: 2px; font-size: 20px; }
.stars .off { color: var(--paper-3); }
.rewards { display: flex; gap: 6px; align-items: center; }
.mini { width: 46px; height: 62px; border-radius: 8px; display: grid; place-items: center; border: 2px solid rgba(0,0,0,.12); }
.mini svg { width: 26px; height: 26px; }
.mini.locked { background: var(--paper-3); color: rgba(35,40,63,.35); }
.stop-actions { grid-column: 2 / -1; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.content-note { margin-top: 26px; }

/* Cards */
.cardgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 18px; }
.card {
  --frame: var(--sage); --art: linear-gradient(160deg, #9fbe95, #5f7d5a);
  position: relative; border-radius: 16px; padding: 8px; background: var(--frame);
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.18), var(--shadow);
  color: var(--ink); display: flex; flex-direction: column; text-align: left;
  border: 0; cursor: default;
}
.card.rare { --frame: var(--sky); --art: linear-gradient(160deg, #8fc0e6, #2f6a9c); }
.card.epic { --frame: var(--plum); --art: linear-gradient(160deg, #c39ad2, #5f3570); }
.card.legendary { --frame: var(--gold); --art: linear-gradient(160deg, #ffe39a, #c07f1c); }
.card .art { height: 118px; border-radius: 10px 10px 4px 4px; background: var(--art); display: grid; place-items: center; color: rgba(255, 249, 232, .95); position: relative; overflow: hidden; }
.card .art svg { width: 70px; height: 70px; filter: drop-shadow(0 3px 0 rgba(0,0,0,.18)); }
.card .art::after { content: ''; position: absolute; inset: auto -20% -40% -20%; height: 60%; background: rgba(255,255,255,.12); border-radius: 50%; }
.card .lvl { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.35); color: #fff; font-weight: 900; font-size: 12px; padding: 2px 8px; border-radius: 999px; z-index: 1; }
.card .rar { position: absolute; top: 8px; right: 8px; background: rgba(255,255,255,.85); color: var(--ink); font-weight: 900; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; padding: 2px 8px; border-radius: 999px; z-index: 1; }
.card .body { background: #fffaf0; border-radius: 4px 4px 10px 10px; padding: 10px 10px 12px; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.card .name { font-family: var(--display); font-weight: 800; font-size: 18px; line-height: 1.1; font-variation-settings: 'SOFT' 100; }
.card .statrow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.card .stat { background: var(--paper-2); border-radius: 8px; text-align: center; padding: 3px 0 2px; }
.card .stat b { display: block; font-size: 18px; line-height: 1.1; }
.card .stat small { font-size: 11px; font-weight: 800; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; }
.card .stat.hot { background: var(--wheat-soft); outline: 2px solid var(--wheat); }
.card .ability { font-size: 13px; line-height: 1.3; }
.card .ability b { display: block; font-size: 13px; }
.card .quote { font-size: 12.5px; color: var(--ink-soft); font-style: italic; }
.card.locked { --frame: #cbbd9f; filter: saturate(.2); }
.card.locked .art { background: #b9aa8a; color: rgba(35,40,63,.4); }
.card.locked .name { color: var(--ink-soft); }
.card .foot { margin-top: auto; display: flex; gap: 6px; align-items: center; justify-content: space-between; }
button.card { cursor: pointer; transition: transform .12s ease; }
button.card:hover:not(:disabled) { transform: translateY(-4px) rotate(-.6deg); }
button.card.picked { outline: 4px solid var(--barn); outline-offset: 3px; }
button.card:disabled { opacity: .45; cursor: not-allowed; }

.filters { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.sectionhead { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.sectionhead h1 { font-size: clamp(30px, 5vw, 42px); }

/* Talk */
.talk { display: grid; grid-template-columns: 1fr 300px; gap: 24px; align-items: start; }
.chat { display: flex; flex-direction: column; min-height: 60vh; }
.chathead { display: flex; align-items: center; gap: 14px; padding-bottom: 14px; border-bottom: 2px dashed var(--line); margin-bottom: 14px; }
.page-avatar { flex: none; width: 52px; height: 52px; border-radius: 50%; background: var(--sky); display: grid; place-items: center; color: #fff; box-shadow: inset 0 -4px 0 rgba(0,0,0,.2); }
.page-avatar svg { width: 30px; height: 30px; }
.page-avatar.thinking { animation: bob 1s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-4px); } }
.ai-pill { font-size: 12px; font-weight: 900; background: var(--sky); color: #fff; border-radius: 999px; padding: 1px 8px; vertical-align: middle; }
.msgs { display: flex; flex-direction: column; gap: 12px; flex: 1; padding: 4px 2px 16px; }
.msg { max-width: 82%; padding: 12px 16px; border-radius: 18px; font-size: 18px; animation: pop .25s ease; }
.msg.page { background: #e7f0f8; border: 2px solid #c9dbec; border-bottom-left-radius: 6px; align-self: flex-start; }
.msg.reader { background: var(--ink); color: var(--paper); border-bottom-right-radius: 6px; align-self: flex-end; }
.msg.typing { color: var(--ink-soft); }
.msg.typing span { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: currentColor; margin: 0 2px; animation: blink 1s infinite; }
.msg.typing span:nth-child(2) { animation-delay: .15s; } .msg.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 50% { opacity: .2; } }
@keyframes pop { from { transform: translateY(6px); opacity: 0; } }
.composer { border-top: 2px dashed var(--line); padding-top: 14px; display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: end; }
.composer textarea { width: 100%; resize: none; min-height: 56px; max-height: 160px; border-radius: 14px; border: 2px solid var(--line); background: #fff; padding: 14px; font: inherit; font-size: 18px; color: var(--ink); }
.composer textarea:focus { outline: 3px solid rgba(63, 127, 181, .35); border-color: var(--sky); }
.micbtn { width: 56px; height: 56px; border-radius: 50%; border: 0; cursor: pointer; background: var(--sky); color: #fff; display: grid; place-items: center; box-shadow: inset 0 -4px 0 rgba(0,0,0,.2); }
.micbtn svg { width: 28px; height: 28px; }
.micbtn.live { background: var(--barn); animation: pulse 1.2s infinite; }
.micbtn:disabled { opacity: .4; cursor: not-allowed; }
.side { display: grid; gap: 16px; }
.ideas { display: flex; gap: 8px; margin: 8px 0 4px; }
.idea { width: 36px; height: 36px; border-radius: 50%; border: 3px dashed var(--paper-3); display: grid; place-items: center; }
.idea.got { border: 3px solid var(--sage); background: var(--sage); color: #fff; animation: pop .3s ease; }
.idea svg { width: 18px; height: 18px; }
.turns { font-weight: 800; }
.toggle { display: flex; align-items: center; gap: 8px; font-weight: 800; cursor: pointer; }
.toggle input { width: 20px; height: 20px; accent-color: var(--sky); }
.result { border-radius: var(--radius); padding: 18px; border: 2px solid; }
.result.notyet { background: #fdf0e2; border-color: var(--wheat); }
.result.care { background: #eef4fb; border-color: var(--sky); }

/* Onboarding */
.welcome { max-width: 520px; margin: 6vh auto 0; text-align: center; }
.welcome h1 { font-size: 44px; margin-bottom: 8px; }
.welcome input { width: 100%; font: inherit; font-size: 20px; padding: 14px 16px; border-radius: 14px; border: 2px solid var(--line); margin: 14px 0; text-align: center; }

/* Overlay: rewards */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(35, 40, 63, .72); display: grid; place-items: center; padding: 16px; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; } }
.reward { background: var(--paper); border-radius: 24px; padding: 28px; max-width: 640px; width: 100%; text-align: center; box-shadow: 0 30px 60px -20px rgba(0,0,0,.5); max-height: calc(100vh - 32px); overflow: auto; }
.reward h2 { font-size: 34px; margin: 6px 0; }
.reward .stars { font-size: 34px; }
.reveal { display: flex; justify-content: center; gap: 16px; flex-wrap: wrap; margin: 20px 0; perspective: 900px; }
.flip { width: 200px; height: 330px; position: relative; transform-style: preserve-3d; transition: transform .8s cubic-bezier(.3,1.4,.5,1); cursor: pointer; border: 0; background: none; padding: 0; }
.flip.open { transform: rotateY(180deg); }
.flip .face { position: absolute; inset: 0; backface-visibility: hidden; }
.flip .back { border-radius: 16px; background: repeating-linear-gradient(45deg, var(--barn) 0 14px, var(--barn-dark) 14px 28px); display: grid; place-items: center; color: var(--paper); font-family: var(--display); font-weight: 800; font-size: 20px; box-shadow: var(--shadow); }
.flip .front { transform: rotateY(180deg); }
.flip .front .card { height: 100%; }
.inkgain { display: inline-flex; align-items: center; gap: 8px; font-weight: 900; font-size: 20px; background: #fff; border-radius: 999px; padding: 6px 16px; border: 2px solid var(--line); }

/* Duel */
.rivals { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.rival { text-align: left; cursor: pointer; border: 2px solid var(--line); border-radius: var(--radius); background: #fffaf0; padding: 18px; box-shadow: var(--shadow); transition: transform .12s; }
.rival:hover { transform: translateY(-3px); }
.rival h3 { font-size: 22px; }
.rival .pow { font-weight: 900; font-size: 13px; color: var(--barn); margin-top: 8px; }
.arena { display: grid; gap: 18px; }
.scoreboard { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 14px; }
.scoreboard .side-name { font-family: var(--display); font-weight: 800; font-size: 22px; }
.scoreboard .score { font-family: var(--display); font-weight: 800; font-size: 44px; text-align: center; }
.scoreboard .right { text-align: right; }
.trial { text-align: center; padding: 16px; border-radius: var(--radius); background: var(--ink); color: var(--paper); }
.trial .round { font-weight: 900; letter-spacing: .08em; text-transform: uppercase; font-size: 13px; color: var(--wheat-soft); }
.trial h2 { font-size: 30px; margin-top: 4px; }
.trial .stat-chip { display: inline-block; margin-top: 6px; background: var(--wheat); color: var(--ink); font-weight: 900; padding: 2px 12px; border-radius: 999px; }
.clash { display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: center; justify-items: center; }
.clash .vs { font-family: var(--display); font-weight: 800; font-size: 32px; color: var(--barn); }
.clash .card { width: 200px; }
.clash .val { font-family: var(--display); font-weight: 800; font-size: 40px; text-align: center; }
.clash .win { color: var(--sage); }
.clash .notes { font-size: 13px; color: var(--ink-soft); text-align: center; min-height: 18px; }
.facedown { width: 200px; height: 300px; border-radius: 16px; background: repeating-linear-gradient(45deg, var(--ink) 0 14px, #343a56 14px 28px); box-shadow: var(--shadow); display: grid; place-items: center; color: var(--paper); font-family: var(--display); font-weight: 800; }
.hand { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.pips { display: flex; gap: 6px; justify-content: center; }
.pip { width: 14px; height: 14px; border-radius: 50%; background: var(--paper-3); }
.pip.w { background: var(--sage); } .pip.l { background: var(--barn); } .pip.t { background: var(--wheat); }

@media (max-width: 820px) {
  .hero, .talk { grid-template-columns: 1fr; }
  .bookrow, .bookhead { grid-template-columns: 110px 1fr; gap: 16px; }
  .cover .t { font-size: 17px; }
  .stop { grid-template-columns: 52px 1fr; }
  .stop .badge { width: 52px; height: 52px; font-size: 22px; }
  .stop:not(:last-child)::after { left: 43px; }
  .stop .rewards { grid-column: 2; }
  .topbar { gap: 8px; }
  .tabs { gap: 0; }
  .tabs a { padding: 6px 9px; font-size: 14px; white-space: nowrap; }
  .wallet { padding: 3px 9px 3px 6px; }
  .composer { grid-template-columns: auto 1fr; }
  .composer textarea { grid-column: 1 / -1; grid-row: 1; }
  .composer #send { justify-self: end; }
  .brand span:last-child { display: none; }
  .clash .card, .facedown { width: 140px; }
  .facedown { height: 210px; }
  .clash .card .art { height: 70px; }
  .clash .card .ability, .clash .card .quote { display: none; }
  .msg { max-width: 92%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
