:root {
  --paper: #e3dbc4;
  --paper-2: #ebe5d3;
  --edge: #c9bb9c;
  --blue: #5b93dc;
  --blue-d: #3f74bd;
  --ink: #6e5946;
  --ink-d: #4d3d30;
  --bg: #d3c8ab;
  --radius: 18px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Fredoka", system-ui, sans-serif;
  color: var(--ink-d);
  background-color: var(--bg);
  background-image:
    radial-gradient(rgba(110, 89, 70, .16) 1.4px, transparent 1.6px);
  background-size: 14px 14px;
  min-height: 100vh;
}

.top {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  max-width: 1320px; margin: 0 auto; padding: 22px 24px 8px;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 26px; font-weight: 700; color: var(--blue); letter-spacing: .02em; }
.brand b { color: var(--ink-d); font-weight: 600; }

.layout {
  max-width: 1320px; margin: 0 auto; padding: 12px 24px 48px;
  display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 28px; align-items: start;
}
.preview { position: sticky; top: 16px; }
.canvas-wrap {
  position: relative; border-radius: 26px; padding: 14px;
  background: #b9ab8b; box-shadow: 0 2px 0 #a8997a inset, 0 18px 40px -18px rgba(60, 45, 30, .5);
}
.canvas-wrap.drag { outline: 4px dashed var(--blue); outline-offset: 4px; }
canvas { display: block; width: 100%; height: auto; border-radius: 16px; touch-action: none; }
.hint { margin: 10px 4px 0; font-size: 14px; color: #f4efe2; text-align: center; }

.actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.btn {
  font: inherit; font-weight: 600; font-size: 16px; cursor: pointer;
  border: 2px solid var(--edge); background: var(--paper-2); color: var(--ink-d);
  padding: 11px 18px; border-radius: 14px; box-shadow: 0 3px 0 var(--edge);
  transition: transform .08s, box-shadow .08s, background .15s;
}
.btn:hover { background: #f3eee0; }
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--edge); }
.btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
/* text fields: no blue ring, just a slightly darker border while typing */
input:focus, select:focus { outline: none; }
input[type="text"]:focus, input[type="date"]:focus, select:focus { border-color: var(--ink); }
.btn.primary { background: var(--blue); color: #fff; border-color: var(--blue-d); box-shadow: 0 3px 0 var(--blue-d); }
.btn.primary:hover { background: #6aa0e6; }
.story-btn { display: inline-flex; align-items: center; gap: 8px; }
.story-btn svg { width: 20px; height: 20px; flex: none; }
.story-btn.nudge { animation: nudge 1.1s ease-in-out 2; }
@keyframes nudge {
  0%, 100% { transform: scale(1); box-shadow: 0 3px 0 var(--blue-d), 0 0 0 0 rgba(91, 147, 220, .55); }
  50% { transform: scale(1.05); box-shadow: 0 3px 0 var(--blue-d), 0 0 0 10px rgba(91, 147, 220, 0); }
}
@media (prefers-reduced-motion: reduce) { .story-btn.nudge { animation: none; } }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.req { font-size: 12px; font-weight: 600; color: #c4433a; text-transform: uppercase; letter-spacing: .04em; margin-left: 4px; }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--ink); }
.btn.small { padding: 8px 12px; font-size: 14px; }
.btn.dice { padding: 8px; display: grid; place-items: center; align-self: end; height: 46px; width: 46px; }
.btn.dice svg { width: 24px; height: 24px; fill: currentColor; }
.btn.icon-btn { padding: 0; width: 48px; flex: none; align-self: stretch; display: grid; place-items: center; color: var(--ink); }
.btn.icon-btn svg { width: 22px; height: 22px; }

.controls { display: grid; gap: 16px; }
.card {
  margin: 0; border: 2px solid var(--edge); border-radius: var(--radius);
  background: var(--paper); padding: 16px 16px 18px; display: grid; gap: 12px;
  box-shadow: 0 4px 0 var(--edge);
}
legend {
  font-weight: 700; color: var(--blue); font-size: 18px; letter-spacing: .04em; text-transform: uppercase;
  background: var(--paper); padding: 2px 10px; border-radius: 10px; border: 2px solid var(--edge);
}
label, .lbl { display: grid; gap: 5px; font-weight: 600; font-size: 14px; color: var(--blue-d); }
input[type="text"], input[type="date"], select {
  font: inherit; font-size: 17px; font-weight: 600; color: var(--ink-d);
  width: 100%; padding: 10px 12px; border-radius: 12px;
  border: 2px solid var(--edge); background: var(--paper-2);
}
#name { font-family: "Darumadrop One", "Fredoka", sans-serif; font-size: 19px; padding: 7px 12px; }
input[type="range"] { width: 100%; accent-color: var(--blue); }
.row { display: flex; gap: 10px; align-items: end; }
.grow { flex: 1; min-width: 0; }
.note { margin: -4px 0 0; font-size: 13px; color: var(--ink); }
.oss-links { display: flex; gap: 10px; flex-wrap: wrap; }
.oss-links .btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; flex: 1 1 auto; white-space: nowrap; padding-left: 14px; padding-right: 14px; }
.oss-links svg { width: 18px; height: 18px; }

.combo { display: flex; align-items: stretch; }
.combo .prefix {
  display: grid; place-items: center; min-width: 40px; font-size: 18px; font-weight: 700; color: #fff;
  background: var(--blue); border-radius: 12px 0 0 12px; border: 2px solid var(--blue-d); border-right: 0;
}
.combo input { border-radius: 0 12px 12px 0; letter-spacing: .08em; }


.upload {
  display: flex; align-items: center; gap: 12px; cursor: pointer; color: var(--ink-d);
  padding: 14px; border: 2px dashed var(--edge); border-radius: 14px; background: var(--paper-2);
}
.upload:hover { border-color: var(--blue); }
.upload:focus-within { outline: 3px solid var(--blue); outline-offset: 2px; }
.upload input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload-icon { width: 46px; height: 46px; flex: none; display: grid; place-items: center; border-radius: 12px; background: var(--blue); color: #fff; }
.upload-icon svg { width: 26px; height: 26px; }
.upload b { display: block; font-size: 17px; }
.upload small { display: block; font-weight: 500; color: var(--ink); font-size: 13px; }


.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer;
  padding: 7px 12px; border-radius: 999px; border: 2px solid var(--edge);
  background: var(--paper-2); color: var(--ink);
}
.chip[aria-pressed="true"] { background: var(--c); border-color: var(--c); color: #fff; }

/* ascent picker */
#ascentLbl { display: flex; gap: 6px; align-items: baseline; }
.ascent-name { color: var(--ink); font-weight: 500; }
.ascents { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.ascent-opt {
  font: inherit; cursor: pointer; display: grid; justify-items: center; gap: 4px;
  padding: 6px 2px 5px; border-radius: 12px; border: 2px solid transparent; background: none; color: var(--ink);
}
.ascent-opt:hover { background: var(--paper-2); }
.ascent-opt:focus-visible { outline: 3px solid var(--blue); outline-offset: 1px; }
.ascent-opt[aria-checked="true"] { background: var(--paper-2); border-color: var(--blue); color: var(--blue-d); }
.ascent-dot {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: var(--c); border: 3px solid var(--d);
}
.ascent-opt.cosmic .ascent-dot {
  background: radial-gradient(circle at 35% 35%, #3b4fa8, #1d2a66 60%, #0b0f2a),
    radial-gradient(circle, #ffe9a8 1px, transparent 1.5px) 0 0 / 9px 9px;
  background-blend-mode: screen;
}
.ascent-dot span {
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  background: #fff6df; color: var(--ink-d); font-weight: 700; font-size: 13px; line-height: 1;
}
.ascent-cap { font-size: 11.5px; font-weight: 600; line-height: 1.1; text-align: center; }

.legal { margin: 2px 0 0; font-size: 12px; color: var(--ink); }

/* creator credit (page only, never drawn on exports) */
.credit { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; margin-top: 4px; color: var(--ink); font-weight: 500; }
.credit p { margin: 0; }
.credit b { color: var(--ink-d); font-weight: 600; }
.heart { color: #d24f43; }
.socials { display: flex; gap: 8px; }
.socials a {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; color: var(--ink-d);
  background: var(--paper-2); border: 2px solid var(--edge); box-shadow: 0 3px 0 var(--edge);
}
.socials a:hover { color: var(--blue); border-color: var(--blue); }
.socials a:active { transform: translateY(3px); box-shadow: none; }
.socials a:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.socials svg { width: 20px; height: 20px; fill: currentColor; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; padding: 8px 16px 40px; }
  .top { padding: 18px 16px 6px; }
  .preview { position: static; }
  .canvas-wrap { padding: 8px; border-radius: 18px; }
  canvas { border-radius: 12px; }
}

/* story layout picker */
.story-dlg {
  width: min(600px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 20px;
  border: 2px solid var(--edge); border-radius: var(--radius); background: var(--paper); color: var(--ink-d);
  box-shadow: 0 6px 0 var(--edge), 0 24px 60px rgba(77, 61, 48, .35);
}
.story-dlg::backdrop { background: rgba(77, 61, 48, .45); }
.story-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.story-head h2 { margin: 0; font-size: 22px; color: var(--blue); }
.story-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 14px; }
.story-opt {
  display: flex; flex-direction: column; gap: 8px; padding: 8px; cursor: pointer;
  font: 600 15px Fredoka, system-ui, sans-serif; color: var(--ink-d);
  background: var(--paper-2); border: 2px solid var(--edge); border-radius: 14px; box-shadow: 0 3px 0 var(--edge);
}
.story-opt:hover { border-color: var(--blue); }
.story-opt[aria-checked="true"] { border-color: var(--blue); background: #e3ecf8; box-shadow: 0 3px 0 var(--blue-d); }
.story-opt[aria-checked="true"] span { color: var(--blue-d); }
.story-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.story-actions .btn { min-width: 120px; }
@media (max-width: 560px) { .story-actions .btn { flex: 1; } }
.story-opt:active { transform: translateY(3px); box-shadow: none; }
.story-opt:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.story-opt img { width: 100%; aspect-ratio: 9 / 16; border-radius: 8px; display: block; }
@media (max-width: 560px) {
  .story-grid { gap: 8px; } .story-opt { padding: 6px; font-size: 14px; }
  .actions { flex-wrap: nowrap; gap: 8px; }
  .actions .btn { padding-left: 14px; padding-right: 14px; }
  .actions .story-btn { flex: 1 1 auto; justify-content: center; }
  .actions .btn.icon-btn { padding: 0; }
  .actions .btn { white-space: nowrap; }
}
@media (max-width: 360px) {
  .actions { gap: 6px; }
  .actions .btn { font-size: 14px; padding-left: 10px; padding-right: 10px; }
  .actions .btn.icon-btn { width: 42px; padding: 0; }
  .story-btn svg { width: 17px; height: 17px; }
}
