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

:root {
  --paper: #e9e4f5;
  --white: #ffffff;
  --ink: #1b1230;
  --muted: #5b4f78;
  --grape: #7a3cff;
  --grape-soft: #e2d4ff;
  --bile: #b7e34a;
  --gold: #ffc933;
  --pink: #ff5fa2;
  --line: 2px solid var(--ink);
  --shadow: 4px 4px 0 var(--ink);
  --display: "Bagel Fat One", "Arial Black", system-ui, sans-serif;
}

html { color-scheme: light; }

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--paper);
  background-image: radial-gradient(circle at 1px 1px, rgba(27, 18, 48, .14) 1px, transparent 0);
  background-size: 22px 22px;
  color: var(--ink);
  font: 16px/1.5 "Bricolage Grotesque", system-ui, sans-serif;
}

:focus-visible { outline: 3px solid var(--grape); outline-offset: 2px; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { font-family: var(--display); font-weight: 400; line-height: 1.1; }
h2 { font-size: 1.6rem; }
h3 { font-size: 1.2rem; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }

/* ---------- layout ---------- */

.shell { max-width: 1180px; margin: 0 auto; padding: 20px 16px 72px; }

.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px;
  margin-bottom: 20px;
}
.topbar h1 { font-size: clamp(2rem, 5vw, 2.9rem); margin-right: auto; }
.topbar .mascot {
  width: 1.4em; height: 1.4em; margin-right: .15em; vertical-align: -.3em;
  object-fit: cover; background: var(--white); border: var(--line); border-radius: 50%;
  box-shadow: 3px 3px 0 var(--ink);
}

.banner {
  background: var(--gold); border: var(--line); border-radius: 12px;
  padding: 10px 14px; margin-bottom: 20px; font-weight: 700;
}

.grid { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 24px; align-items: start; }
.cauldron { position: sticky; top: 16px; }
@media (max-width: 880px) {
  .grid { grid-template-columns: 1fr; }
  .cauldron { position: static; }
}

.panel {
  background: var(--white); border: var(--line); border-radius: 18px;
  box-shadow: var(--shadow); padding: 20px;
}
.panel + .panel { margin-top: 20px; }
.panel-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 14px; }
.panel-head p { flex-basis: 100%; }

/* ---------- controls ---------- */

.btn {
  font: inherit; font-weight: 700; color: var(--ink); background: var(--white);
  border: var(--line); border-radius: 12px; padding: .5em 1em; white-space: nowrap;
  box-shadow: 3px 3px 0 var(--ink); cursor: pointer;
  transition: transform .08s, box-shadow .08s;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
.btn.primary { background: var(--grape); color: var(--white); }
.btn.warn { background: var(--pink); }
.btn[disabled] { opacity: .55; cursor: default; transform: none; box-shadow: 3px 3px 0 var(--ink); }

.icon-btn {
  font: inherit; font-weight: 700; width: 34px; height: 34px; padding: 0; line-height: 1;
  color: var(--ink); background: var(--white); border: var(--line); border-radius: 10px; cursor: pointer;
}
.icon-btn:hover { background: var(--pink); }

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  font: inherit; color: var(--ink); background: var(--white);
  border: var(--line); border-radius: 10px; padding: .45em .7em; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 120px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-weight: 700; }

.chip {
  font: inherit; font-weight: 700; font-size: .9rem; color: var(--ink); background: var(--white);
  border: var(--line); border-radius: 999px; padding: .15em .8em; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--white); }

.switch {
  appearance: none; -webkit-appearance: none; flex: none; position: relative; cursor: pointer;
  width: 46px; height: 26px; margin: 0; background: var(--paper); border: var(--line); border-radius: 999px;
  transition: background .15s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  background: var(--ink); border-radius: 50%; transition: transform .15s;
}
.switch:checked { background: var(--bile); }
.switch:checked::after { transform: translateX(20px); }

input[type="range"] { width: 100%; accent-color: var(--grape); }

/* ---------- tabs ---------- */

.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.tab {
  font: inherit; font-weight: 700; color: var(--ink); background: var(--white);
  border: var(--line); border-radius: 12px; padding: .45em 1.1em; cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--ink); color: var(--white); }

/* ---------- cauldron ---------- */

.cauldron .names { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }

.cast-btn {
  width: 100%; font-family: var(--display); font-size: 1.7rem; padding: .35em 0;
  background: var(--bile); color: var(--ink); border: var(--line); border-radius: 14px;
  box-shadow: var(--shadow); cursor: pointer; transition: transform .08s, box-shadow .08s;
}
.cast-btn:hover { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--ink); }
.cast-btn:active { transform: translate(4px, 4px); box-shadow: 0 0 0 var(--ink); }
.cast-btn[disabled] { cursor: default; }
.cast-btn.stirring { animation: wobble .65s ease-in-out; }

.result {
  margin-top: 16px; min-height: 190px; padding: 18px; background: var(--paper);
  border: var(--line); border-radius: 18px;
  display: flex; flex-direction: column; justify-content: center; gap: 10px;
}
.result .intro { font-weight: 500; }
.result .spell { font-family: var(--display); font-size: clamp(1.6rem, 3.4vw, 2.1rem); line-height: 1.1; overflow-wrap: anywhere; }
.result.rare { background: var(--grape-soft); }
.result.legendary { background: repeating-linear-gradient(135deg, #ffd84d 0 14px, #ffc933 14px 28px); }
.result.fizzle { background: #e7e5ec; color: var(--muted); }
.result.reveal { animation: flip .55s cubic-bezier(.2, .8, .3, 1.2); }
.result.reveal.crit { animation: flip .55s cubic-bezier(.2, .8, .3, 1.2), shake .4s .55s; }
.result .crit-note { font-weight: 700; }
.result .meta { font-weight: 700; }

.mini-stats { display: flex; gap: 16px; margin-top: 16px; }
.mini-stats div { flex: 1; }
.mini-stats strong { display: block; font-family: var(--display); font-weight: 400; font-size: 1.5rem; line-height: 1.1; }

/* ---------- badges, tags, status ---------- */

.badge {
  font: inherit; font-weight: 700; font-size: .8rem; min-width: 5.6rem; text-align: center;
  color: var(--ink); border: var(--line); border-radius: 999px; padding: .1em .7em; cursor: pointer;
}
.badge.common { background: #dcd6ee; }
.badge.rare { background: var(--grape); color: var(--white); }
.badge.legendary { background: var(--gold); }
.badge.static { cursor: default; }

.tag {
  font-size: .8rem; font-weight: 500; color: var(--muted); border: 2px solid rgba(27, 18, 48, .25);
  border-radius: 8px; padding: 0 .5em; white-space: nowrap;
}

.pill { font-weight: 700; font-size: .9rem; border: var(--line); border-radius: 999px; padding: .2em .9em; background: var(--white); }
.pill.on { background: var(--bile); }
.pill.off { background: #e7e5ec; color: var(--muted); }

/* ---------- lists ---------- */

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar .grow { flex: 1 1 200px; }
.toolbar select { width: auto; }

.add-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin: 14px 0 6px; }
.add-form > input:first-child, .add-form > textarea { grid-column: 1 / -1; }
.add-form > textarea { order: -1; }
@media (max-width: 480px) { .add-form { grid-template-columns: 1fr 1fr; } .add-form > button { grid-column: 1 / -1; } }
.add-extras { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.link-btn { font: inherit; font-weight: 700; color: var(--grape); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }

ul.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: grid; grid-template-columns: auto 1fr auto auto auto; gap: 10px; align-items: center;
  padding: 9px 0; border-bottom: 2px dashed rgba(27, 18, 48, .18);
}
.row.off .text-btn, .row.off .tag { opacity: .45; }
.row.flash { animation: flash 1.4s ease-out; }
.row.editing { grid-template-columns: 1fr; padding: 12px 0; }
.row.lines { grid-template-columns: 1fr auto auto; }
.edit-form { display: grid; grid-template-columns: 1fr 180px auto auto; gap: 8px; }
.edit-form.single { grid-template-columns: 1fr auto auto; }
@media (max-width: 720px) {
  .row { grid-template-columns: auto 1fr auto auto; }
  .row .tag { display: none; }
  .edit-form, .edit-form.single { grid-template-columns: 1fr 1fr; }
  .edit-form input:first-child { grid-column: 1 / -1; }
}
.text-btn {
  font: inherit; text-align: left; color: var(--ink); background: none; border: 0; padding: 2px 4px;
  border-radius: 6px; cursor: text; overflow-wrap: anywhere;
}
.text-btn:hover { background: var(--grape-soft); }
.empty { padding: 28px 8px; text-align: center; color: var(--muted); }

.hints { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.hints code { font: inherit; font-weight: 700; background: var(--grape-soft); border: 2px solid var(--ink); border-radius: 8px; padding: 0 .5em; cursor: pointer; }
.line-add { display: flex; gap: 8px; margin: 10px 0 6px; }

/* ---------- odds ---------- */

.odds { display: grid; gap: 18px; }
.odds .head { display: flex; justify-content: space-between; gap: 12px; font-weight: 700; }
.odds output { font-family: var(--display); font-size: 1.2rem; }
.bar { display: flex; height: 34px; border: var(--line); border-radius: 10px; overflow: hidden; margin: 8px 0; }
.bar span { display: block; min-width: 0; }
.bar .s-fizzle { background: #cfcbd9; }
.bar .s-legendary { background: var(--gold); }
.bar .s-rare { background: var(--grape); }
.bar .s-common { background: #dcd6ee; }
.saved { font-weight: 700; color: var(--muted); }

/* ---------- log ---------- */

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { border: var(--line); border-radius: 12px; padding: 10px 12px; background: var(--paper); }
.stat strong { display: block; font-family: var(--display); font-weight: 400; font-size: 1.8rem; line-height: 1.1; }
.boards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 18px; }
@media (max-width: 720px) { .boards { grid-template-columns: 1fr; } }
.boards ol { margin: 6px 0 0; padding-left: 1.4em; }
.log-row { display: grid; grid-template-columns: 4.5rem 1fr auto; gap: 10px; align-items: baseline; padding: 8px 0; border-bottom: 2px dashed rgba(27, 18, 48, .18); }
.log-row .when { color: var(--muted); font-size: .9rem; }
@media (max-width: 720px) { .log-row { grid-template-columns: 1fr; gap: 2px; } }

/* ---------- daily curse and suggestions ---------- */

.daily { display: grid; gap: 18px; }
.switch-line { display: flex; align-items: center; gap: 12px; font-weight: 700; cursor: pointer; }
.daily-fields { display: grid; grid-template-columns: 9rem 1fr; gap: 12px; align-items: end; }
@media (max-width: 560px) { .daily-fields { grid-template-columns: 1fr; } }
.tz-row { display: flex; gap: 8px; }
.tz-row .btn { white-space: nowrap; font-weight: 700; }

.suggestion { display: grid; gap: 6px; padding: 12px 0; border-bottom: 2px dashed rgba(27, 18, 48, .18); }
.suggestion .controls { display: flex; flex-wrap: wrap; gap: 8px; }
.suggestion .controls select { width: auto; }
.suggestion .controls input { flex: 1 1 140px; width: auto; }

.rows.results:not(:empty) {
  background: var(--paper); border: var(--line); border-radius: 12px; padding: 0 12px; margin: 8px 0 14px;
}
.rows.results .row:last-child { border-bottom: 0; }

.ach { margin-bottom: 18px; }
.ach p { margin: 4px 0; }

/* ---------- bot profile ---------- */

.profile { display: grid; grid-template-columns: auto 1fr; gap: 24px; align-items: start; }
@media (max-width: 560px) { .profile { grid-template-columns: 1fr; } }
.profile-fields { display: grid; gap: 12px; }
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px; cursor: pointer;
  border: 2px dashed var(--ink); border-radius: 18px; background: var(--paper); font-weight: 700;
}
.drop:hover, .drop.over { background: var(--grape-soft); }
.avatar {
  width: 128px; height: 128px; object-fit: cover; border-radius: 50%;
  border: var(--line); box-shadow: 3px 3px 0 var(--ink); background: var(--white);
}

/* ---------- login ---------- */

.login { max-width: 420px; margin: 12vh auto 0; }
.login h1 { font-size: 2.6rem; margin-bottom: 6px; }
.login form { display: grid; gap: 12px; margin-top: 18px; }
.error { color: #b00045; font-weight: 700; min-height: 1.5em; }

/* ---------- toasts and confetti ---------- */

#toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 20; width: min(92vw, 420px); }
.toast {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--ink); color: var(--white); border-radius: 12px; padding: 10px 14px; font-weight: 500;
  animation: pop .2s ease-out;
}
.toast.bad { background: #b00045; }
.toast button { font: inherit; font-weight: 700; color: var(--ink); background: var(--bile); border: 0; border-radius: 8px; padding: .2em .8em; cursor: pointer; }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 30; }

/* ---------- motion ---------- */

@keyframes flip { from { transform: perspective(600px) rotateX(90deg) scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes shake { 0%, 100% { transform: none; } 20% { transform: translateX(-8px) rotate(-1deg); } 40% { transform: translateX(8px) rotate(1deg); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }
@keyframes wobble { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(-3deg) scale(1.02); } 40% { transform: rotate(3deg) scale(1.02); } 60% { transform: rotate(-2deg); } 80% { transform: rotate(2deg); } }
@keyframes flash { from { background: var(--gold); } to { background: transparent; } }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
