:root {
  --bg: #160504;
  --bg-soft: #2b0b08;
  --panel: rgba(48, 13, 9, 0.84);
  --panel-strong: rgba(66, 18, 12, 0.97);
  --text: #fff3ea;
  --muted: #d7a792;
  --line: rgba(255, 140, 92, 0.22);
  --accent: linear-gradient(135deg, #ff5a1f, #ff2d20 55%, #ffb14a);
  --accent-solid: #ff5d28;
  --accent-strong: #ffd3a1;
  --danger: #ff7a72;
  --warning: #ffcf66;
  --shadow: 0 28px 70px rgba(0, 0, 0, 0.38);
}

body[data-theme="emerald"] {
  --bg: #04100d;
  --bg-soft: #081a15;
  --panel: rgba(8, 31, 24, 0.84);
  --panel-strong: rgba(10, 42, 31, 0.97);
  --text: #edfff8;
  --muted: #98cdb9;
  --line: rgba(110, 220, 180, 0.18);
  --accent: linear-gradient(135deg, #0b8f63, #18b57f 55%, #7ef7c8);
  --accent-solid: #14a976;
  --accent-strong: #c5ffe8;
  --danger: #ff8d7e;
  --warning: #b7fff0;
  --shadow: 0 28px 70px rgba(0, 0, 0, 0.38);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  min-height: 100vh;
  transition: background 260ms ease, color 220ms ease;
  background:
    radial-gradient(circle at top left, rgba(255, 82, 36, 0.32), transparent 22rem),
    radial-gradient(circle at top right, rgba(255, 177, 74, 0.2), transparent 18rem),
    radial-gradient(circle at bottom center, rgba(138, 17, 8, 0.32), transparent 28rem),
    linear-gradient(180deg, #120403 0%, #1a0705 42%, #160504 100%);
}

body[data-theme="emerald"] {
  background:
    radial-gradient(circle at top left, rgba(20, 168, 116, 0.22), transparent 22rem),
    radial-gradient(circle at top right, rgba(126, 247, 200, 0.12), transparent 18rem),
    radial-gradient(circle at bottom center, rgba(6, 86, 62, 0.22), transparent 28rem),
    linear-gradient(180deg, #030c0a 0%, #071411 42%, #04100d 100%);
}

a { color: var(--accent-strong); text-decoration: none; }
button, input, select, textarea { font: inherit; }

button {
  border: 0;
  border-radius: 1rem;
  padding: 0.82rem 1.05rem;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 0.01em;
  box-shadow: 0 14px 26px rgba(255, 106, 44, 0.24);
  transition: transform 180ms ease, box-shadow 180ms ease, opacity 180ms ease, filter 180ms ease;
}
button:hover { transform: translateY(-1px); box-shadow: 0 18px 32px rgba(255, 106, 44, 0.34); filter: saturate(1.06); }
button:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.ghost-button {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--line);
  box-shadow: none;
}

.shell {
  width: min(1220px, calc(100% - 1.4rem));
  margin: 0 auto;
  padding: 1.2rem 0 2rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.topbar-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.8rem;
}

.toolbar-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 182px;
  justify-content: center;
  background: rgba(255, 227, 210, 0.08);
  border: 1px solid var(--line);
  box-shadow: none;
}

.theme-toggle-icon {
  font-size: 1rem;
}

.theme-toggle-label {
  font-size: 0.92rem;
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent-strong);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; }

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: flex-end;
}

.nav a,
.flash,
.hero-pill {
  backdrop-filter: blur(14px);
  background: rgba(255, 227, 210, 0.06);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.68rem 1rem;
  box-shadow: var(--shadow);
}

.flash {
  margin-bottom: 1rem;
  color: #bff8ea;
}
.flash-error {
  color: #ffd7d7;
  border-color: rgba(255, 107, 107, 0.3);
}

.grid { display: grid; gap: 1rem; }
.stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 1rem; }
.stats-grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.action-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 1rem; }
.action-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.entity-grid { grid-template-columns: minmax(0, 380px) minmax(0, 1fr); margin-bottom: 1rem; }

.card {
  background:
    linear-gradient(180deg, rgba(68, 15, 10, 0.96), rgba(30, 8, 7, 0.98)),
    radial-gradient(circle at top, rgba(255, 171, 94, 0.1), transparent 42%);
  border: 1px solid var(--line);
  border-radius: 1.45rem;
  padding: 1rem;
  box-shadow: var(--shadow);
  transition: background 220ms ease, border-color 220ms ease, transform 180ms ease, box-shadow 220ms ease;
}

.hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  position: relative;
  overflow: hidden;
}

.hero::after {
  content: "";
  position: absolute;
  inset: auto -10% -45% auto;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 181, 71, 0.16), transparent 68%);
  pointer-events: none;
  transition: background 240ms ease;
}

.hero h2 { margin-bottom: 0.45rem; }
.hero-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: flex-end;
}

.stat span {
  display: block;
  font-size: 2.1rem;
  font-weight: 800;
  margin-bottom: 0.35rem;
}
.stat label, .muted, .empty { color: var(--muted); }
.pick {
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 0.45rem;
}

.roll-card {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}
.roll-card::before {
  content: "";
  position: absolute;
  inset: -30% auto auto -10%;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 179, 71, 0.18), transparent 70%);
  z-index: -1;
}
.roll-card.is-rolling {
  animation: pulseCard 420ms ease-in-out 2;
}

@keyframes pulseCard {
  0% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-2px) scale(1.015); }
  100% { transform: translateY(0) scale(1); }
}

.card-topline {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}
.dot {
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 18px currentColor;
}
.dot-account { color: #ff8a3d; background: currentColor; }
.dot-coin { color: #ffb347; background: currentColor; }
.dot-combo { color: #ffd166; background: currentColor; }
.dot-method { color: #ff6b4a; background: currentColor; }
.dot-dice { color: #ff7a18; background: currentColor; }
.dot-limbo { color: #ff4f4f; background: currentColor; }

body[data-theme="emerald"] .dot-account { color: #40e08d; }
body[data-theme="emerald"] .dot-coin { color: #89f5b7; }
body[data-theme="emerald"] .dot-combo { color: #d8ff84; }
body[data-theme="emerald"] .dot-method { color: #50d890; }
body[data-theme="emerald"] .dot-dice { color: #1fcf7a; }
body[data-theme="emerald"] .dot-limbo { color: #7ef0b1; }

.status-line { min-height: 2.8rem; }
.section-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 0.8rem;
}
.compact-head { margin-bottom: 0.4rem; }
.section-inline-actions { display: flex; gap: 0.8rem; align-items: center; flex-wrap: wrap; }

.stack { display: grid; gap: 0.9rem; }
label { display: grid; gap: 0.42rem; font-size: 0.95rem; }
input, select, textarea {
  width: 100%;
  border: 1px solid rgba(255, 181, 135, 0.22);
  border-radius: 1rem;
  padding: 0.86rem 0.95rem;
  background: rgba(255, 237, 224, 0.05);
  color: var(--text);
}
textarea { resize: vertical; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 0.9rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid rgba(255, 181, 135, 0.12);
  vertical-align: top;
}

.badge {
  display: inline-flex;
  padding: 0.28rem 0.72rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  border: 1px solid transparent;
}
.badge-active, .badge-hit {
  background: rgba(255, 140, 66, 0.16);
  color: #ffd6ab;
  border-color: rgba(255, 140, 66, 0.3);
}
.badge-watch, .badge-playing {
  background: rgba(255, 194, 107, 0.14);
  color: #ffe2a6;
  border-color: rgba(255, 194, 107, 0.26);
}
.badge-cooldown, .badge-paused {
  background: rgba(255, 111, 76, 0.14);
  color: #ffd0b7;
  border-color: rgba(255, 111, 76, 0.26);
}
.badge-inactive, .badge-archived, .badge-miss {
  background: rgba(255, 77, 77, 0.14);
  color: #ffc0c0;
  border-color: rgba(255, 77, 77, 0.28);
}

body[data-theme="emerald"] .badge-active,
body[data-theme="emerald"] .badge-hit {
  background: rgba(31, 207, 122, 0.16);
  color: #c9ffe1;
  border-color: rgba(31, 207, 122, 0.28);
}

body[data-theme="emerald"] .badge-watch,
body[data-theme="emerald"] .badge-playing {
  background: rgba(126, 240, 177, 0.14);
  color: #d9ffea;
  border-color: rgba(126, 240, 177, 0.24);
}

body[data-theme="emerald"] .badge-cooldown,
body[data-theme="emerald"] .badge-paused {
  background: rgba(216, 255, 132, 0.14);
  color: #eeffc1;
  border-color: rgba(216, 255, 132, 0.24);
}

body[data-theme="emerald"] .badge-inactive,
body[data-theme="emerald"] .badge-archived,
body[data-theme="emerald"] .badge-miss {
  background: rgba(255, 142, 125, 0.14);
  color: #ffd1c9;
  border-color: rgba(255, 142, 125, 0.24);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  align-items: center;
}
.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-strong);
  box-shadow: none;
}
.danger { color: var(--danger); }

.inline-form { margin: 0; }
.logout-form { margin: 0; }
.form-card { position: sticky; top: 1rem; }
.method-grid {
  display: grid;
  gap: 0.9rem;
}
.method-item {
  border: 1px solid rgba(255, 181, 135, 0.14);
  border-radius: 1rem;
  padding: 0.9rem;
  background: rgba(255, 226, 204, 0.03);
}

.game-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.game-history-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.ritual-grid {
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  margin-bottom: 1rem;
}

.ritual-card {
  background:
    linear-gradient(180deg, rgba(77, 18, 12, 0.98), rgba(28, 8, 7, 0.98)),
    radial-gradient(circle at top right, rgba(255, 206, 120, 0.12), transparent 36%);
}

.ritual-main {
  position: relative;
  overflow: hidden;
}

.ritual-main::after {
  content: "";
  position: absolute;
  right: -40px;
  top: -40px;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 183, 92, 0.18), transparent 70%);
  pointer-events: none;
}

.ritual-note {
  font-size: 1.08rem;
  line-height: 1.7;
  color: var(--accent-strong);
}

.fortune-grid { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:0.8rem; margin:1rem 0; }
.fortune-box { padding:0.9rem 1rem; border-radius:1rem; background:rgba(255,226,204,0.05); border:1px solid rgba(255,181,135,0.12); display:grid; gap:0.4rem; }
.fortune-box strong { font-size:1.08rem; }
.fortune-recommend-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:0.9rem; margin-bottom:0.9rem; }
.fortune-recommend { padding:1rem; border-radius:1rem; border:1px solid rgba(255,181,135,0.12); }
.fortune-recommend.good { background:rgba(255,179,71,0.06); }
.fortune-recommend.bad { background:rgba(255,107,74,0.05); }
.fortune-recommend ul { margin:0.7rem 0 0; padding-left:1.1rem; color:var(--muted); }
.fortune-personal-hint { color:var(--accent-strong); font-weight:700; line-height:1.6; margin-bottom:0.8rem; }
.owner-profile-form { margin-bottom:1rem; }
.ritual-form { margin-top: 1rem; }
.ritual-score-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:0.9rem; }
.ritual-checklist { display:grid; gap:0.9rem; margin-top:0.8rem; }
.ritual-check-item {
  display:grid;
  grid-template-columns:auto 1fr;
  gap:0.8rem;
  align-items:flex-start;
  padding:0.9rem 1rem;
  border-radius:1rem;
  background:rgba(255,226,204,0.04);
  border:1px solid rgba(255,181,135,0.12);
}
.ritual-check-item input { width:auto; margin-top:0.15rem; }

.game-card {
  min-height: 240px;
}

.game-pick {
  font-size: 2.4rem;
  margin: 0.8rem 0 0.6rem;
}

.history-list {
  display: grid;
  gap: 0.7rem;
}

.history-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border-radius: 1rem;
  background: rgba(255, 226, 204, 0.04);
  border: 1px solid rgba(255, 181, 135, 0.12);
}

.history-value {
  font-size: 1.1rem;
  font-weight: 800;
}

.history-time {
  color: var(--muted);
  font-size: 0.9rem;
}

.login-shell {
  max-width: 520px;
  margin: 8vh auto 0;
}
.login-card {
  padding: 1.4rem;
  border: 1px solid rgba(255, 181, 135, 0.18);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 122, 24, 0.08) inset;
}
.login-copy { margin-bottom: 1rem; }

body[data-theme="emerald"] .hero::after {
  background: radial-gradient(circle, rgba(126, 247, 200, 0.14), transparent 68%);
}

body[data-theme="emerald"] .card {
  background:
    linear-gradient(180deg, rgba(8, 38, 29, 0.96), rgba(4, 17, 14, 0.98)),
    radial-gradient(circle at top, rgba(126, 247, 200, 0.06), transparent 42%);
}

body[data-theme="emerald"] .theme-toggle {
  background: rgba(183, 255, 216, 0.08);
}

@media (max-width: 980px) {
  .stats-grid-5,
  .action-grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .hero {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 820px) {
  .topbar, .section-head { align-items: start; flex-direction: column; }
  .topbar-actions { width: 100%; align-items: stretch; }
  .toolbar-row { width: 100%; justify-content: space-between; }
  .stats-grid, .stats-grid-5, .action-grid, .action-grid-4, .entity-grid, .ritual-grid, .ritual-score-grid, .fortune-grid, .fortune-recommend-grid { grid-template-columns: 1fr; }
  .game-grid, .game-history-grid { grid-template-columns: 1fr; }
  .nav { width: 100%; justify-content: flex-start; }
  .nav a, .nav span { flex: 1 1 auto; text-align: center; }
  .form-card { position: static; }
}
