:root {
  color-scheme: dark;
  --bg: #0c0914;
  --surface: rgba(28, 22, 45, 0.94);
  --surface-2: rgba(38, 30, 61, 0.92);
  --surface-3: rgba(16, 13, 26, 0.9);
  --text: #f7f2ff;
  --muted: #b9afc9;
  --line: rgba(255, 255, 255, 0.12);
  --accent: #a887ff;
  --accent-2: #74d6ff;
  --accent-soft: rgba(168, 135, 255, 0.18);
  --success: #75e7b1;
  --danger: #ff7f9e;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.32);
  --radius: 20px;
}

body[data-form="idol"] {
  --bg: #150918;
  --surface: rgba(48, 17, 49, 0.94);
  --surface-2: rgba(68, 25, 65, 0.92);
  --surface-3: rgba(25, 8, 27, 0.9);
  --muted: #d7b8d3;
  --line: rgba(255, 235, 166, 0.18);
  --accent: #ff72d2;
  --accent-2: #ffe27a;
  --accent-soft: rgba(255, 114, 210, 0.2);
  --success: #ffdf78;
  --shadow: 0 24px 70px rgba(255, 72, 203, 0.15);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 0%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 36rem),
    radial-gradient(circle at 90% 10%, color-mix(in srgb, var(--accent-2) 12%, transparent), transparent 34rem),
    var(--bg);
  transition: background 500ms ease, color 300ms ease;
}

button, input, select, textarea { font: inherit; }

button {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 0.72rem 1rem;
  color: #120d1d;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-weight: 800;
  cursor: pointer;
  transition: transform 140ms ease, filter 140ms ease, border-color 140ms ease;
}

button:hover { transform: translateY(-1px); filter: brightness(1.07); }
button:active { transform: translateY(0); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent-2) 60%, transparent);
  outline-offset: 2px;
}

button.secondary, .file-button.secondary {
  color: var(--text);
  background: var(--surface-3);
  border-color: var(--line);
}

button.danger { color: #fff; background: linear-gradient(135deg, #bb365d, var(--danger)); }
button.small { padding: 0.5rem 0.72rem; font-size: 0.86rem; }
button.icon-button { padding: 0.15rem 0.55rem; font-size: 1.6rem; color: var(--text); background: transparent; border-color: var(--line); }

input, select, textarea {
  width: 100%;
  margin-top: 0.38rem;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 0.7rem 0.78rem;
  color: var(--text);
  background: rgba(5, 4, 9, 0.42);
}

textarea { resize: vertical; }
label { color: var(--muted); font-size: 0.85rem; font-weight: 700; }

.app-header {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  max-width: 1500px;
  margin: 0 auto;
  padding: 1.6rem clamp(1rem, 3vw, 3rem) 1rem;
}

.app-header h1 { margin: 0.15rem 0 0.2rem; font-size: clamp(1.7rem, 4vw, 2.8rem); line-height: 1; }
.app-header p { margin: 0; }
.header-actions { display: flex; gap: 0.55rem; flex-wrap: wrap; justify-content: flex-end; }
.file-button { display: inline-flex; align-items: center; border: 1px solid; border-radius: 12px; padding: 0.72rem 1rem; font-weight: 800; cursor: pointer; }
.file-button input { display: none; }

.eyebrow { margin: 0; color: var(--accent-2); font-size: 0.73rem; font-weight: 900; letter-spacing: 0.16em; text-transform: uppercase; }
.muted { color: var(--muted); }

.tab-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
  max-width: 1500px;
  margin: 0 auto;
  padding: 0.8rem clamp(1rem, 3vw, 3rem);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(16px);
}

.tab-button { color: var(--muted); background: var(--surface-3); border-color: var(--line); }
.tab-button.active { color: #120d1d; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }

main { position: relative; z-index: 1; max-width: 1500px; margin: 0 auto; padding: 1rem clamp(1rem, 3vw, 3rem) 4rem; }
.tab-panel { display: none; animation: fadeIn 240ms ease; }
.tab-panel.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.15rem;
  background: linear-gradient(150deg, var(--surface), var(--surface-3));
  box-shadow: var(--shadow);
}

.card.featured { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }
.card-heading, .section-heading, .subheading, .dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.card-heading h2, .section-heading h2, .dialog-heading h2 { margin: 0.15rem 0 0; }
.section-heading { margin-bottom: 1rem; }
.section-heading > p { max-width: 50rem; color: var(--muted); }

.hero-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.8fr); gap: 1rem; }
.identity-card { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 1rem; align-items: center; }
.avatar-frame {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border: 2px solid color-mix(in srgb, var(--accent) 65%, transparent);
  border-radius: 26px;
  background: radial-gradient(circle at 50% 25%, var(--accent-soft), transparent 60%), var(--surface-3);
}
.avatar-frame img { width: 100%; height: 100%; object-fit: cover; }
.avatar-fallback { display: grid; place-items: center; height: 100%; font-size: 3rem; font-weight: 950; color: var(--accent-2); }
.form-badge { position: absolute; left: 0.6rem; right: 0.6rem; bottom: 0.6rem; padding: 0.45rem; text-align: center; border-radius: 999px; color: #130d1c; background: linear-gradient(135deg, var(--accent), var(--accent-2)); font-weight: 900; }
.identity-copy { display: grid; gap: 0.85rem; }

.mini-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.8rem; }
.go-live-card { display: flex; flex-direction: column; justify-content: space-between; min-height: 220px; overflow: hidden; position: relative; }
.go-live-card::after { content: "♪"; position: absolute; right: 1rem; top: 0.2rem; font-size: 7rem; line-height: 1; opacity: 0.08; color: var(--accent-2); }
.go-live-card h2 { margin-bottom: 0.35rem; }

.live-switch { display: flex; align-items: center; gap: 0.8rem; padding: 0.9rem; border: 1px solid var(--line); border-radius: 16px; background: var(--surface-3); cursor: pointer; }
.live-switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track { position: relative; width: 62px; height: 34px; flex: 0 0 auto; border-radius: 999px; background: #393345; transition: background 250ms ease; }
.switch-knob { position: absolute; width: 26px; height: 26px; left: 4px; top: 4px; border-radius: 50%; background: #fff; transition: transform 250ms ease; }
.live-switch input:checked + .switch-track { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.live-switch input:checked + .switch-track .switch-knob { transform: translateX(28px); }
.switch-copy { display: grid; }
.switch-copy small { color: var(--muted); }

.stat-strip { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0.7rem; margin: 1rem 0; }
.stat-box { padding: 0.85rem; text-align: center; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.stat-box input { text-align: center; font-size: 1.15rem; font-weight: 900; color: var(--text); }

.dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.hp-display { display: grid; grid-template-columns: 1fr auto 1fr; gap: 0.65rem; align-items: end; margin: 1rem 0; text-align: center; }
.hp-display span { padding-bottom: 0.72rem; font-size: 1.8rem; color: var(--muted); }
.hp-display input { font-size: 1.6rem; text-align: center; font-weight: 900; }
.hp-controls { display: grid; grid-template-columns: 90px 1fr 1fr; gap: 0.55rem; margin-bottom: 0.8rem; }

.pip-row { display: grid; grid-template-columns: repeat(5, minmax(45px, 1fr)); gap: 0.55rem; margin: 1rem 0; }
.pip { aspect-ratio: 1; padding: 0; border-radius: 50%; color: var(--text); background: var(--surface-3); border-color: var(--line); }
.pip.available { color: #140d1d; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }

.status-chip { display: inline-flex; align-items: center; padding: 0.36rem 0.65rem; border: 1px solid var(--line); border-radius: 999px; color: var(--accent-2); background: var(--accent-soft); font-size: 0.78rem; font-weight: 900; }
.weapon-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.65rem; }
.weapon-stats div { padding: 0.75rem; border: 1px solid var(--line); border-radius: 13px; background: rgba(0,0,0,0.12); }
.weapon-stats dt { color: var(--muted); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.08em; }
.weapon-stats dd { margin: 0.25rem 0 0; font-weight: 850; }
.button-row { display: flex; gap: 0.55rem; flex-wrap: wrap; margin-top: 0.85rem; }
.button-row button { flex: 1; }
.spell-details { min-height: 84px; margin-top: 0.7rem; padding: 0.75rem; border: 1px solid var(--line); border-radius: 13px; color: var(--muted); background: rgba(0,0,0,0.12); }
.result-card { margin-top: 1rem; }
.roll-log { min-height: 66px; padding: 0.85rem; border-radius: 13px; background: rgba(0,0,0,0.25); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; }
.roll-line + .roll-line { margin-top: 0.45rem; padding-top: 0.45rem; border-top: 1px dashed var(--line); }

.roll-mode-card { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.segmented { display: flex; gap: 0.35rem; }
.segmented button { color: var(--muted); background: var(--surface-3); border-color: var(--line); }
.segmented button.active { color: #130d1c; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }

.attribute-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.attribute-card { text-align: center; }
.attribute-card h3 { margin: 0; }
.attribute-score { width: 76px; margin: 0.75rem auto; text-align: center; font-size: 1.25rem; font-weight: 900; }
.modifier-button { width: 100%; font-size: 1.25rem; }
.save-button { width: 100%; margin-top: 0.55rem; color: var(--text); background: var(--surface-3); border-color: var(--line); }

.skills-layout, .inventory-layout { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(280px, 0.7fr); gap: 1rem; }
.side-stack { display: grid; gap: 1rem; align-content: start; }
.skill-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.55rem; }
.skill-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 0.6rem; align-items: center; padding: 0.65rem; border: 1px solid var(--line); border-radius: 13px; background: rgba(0,0,0,0.12); }
.skill-marker { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; color: var(--accent-2); background: var(--accent-soft); font-size: 0.72rem; font-weight: 950; }
.skill-row button { padding: 0.48rem 0.7rem; min-width: 56px; }

.slot-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.75rem; margin-bottom: 1.2rem; }
.slot-card { padding: 0.85rem; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.slot-card h3 { margin: 0 0 0.65rem; }
.slot-pips { display: flex; gap: 0.45rem; flex-wrap: wrap; }
.slot-pip { width: 36px; height: 36px; padding: 0; border-radius: 50%; color: var(--text); background: var(--surface-3); border-color: var(--line); }
.slot-pip.available { color: #130d1c; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }

.spell-section { margin-top: 1.5rem; }
.subheading { margin-bottom: 0.75rem; }
.subheading h3 { margin: 0; font-size: 1.35rem; }
.subheading p { margin: 0.25rem 0 0; color: var(--muted); }
.spell-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.8rem; }
.spell-card { position: relative; display: flex; flex-direction: column; min-height: 240px; }
.spell-card h3 { margin: 0.3rem 0 0.45rem; }
.spell-meta { display: flex; gap: 0.4rem; flex-wrap: wrap; color: var(--muted); font-size: 0.8rem; }
.spell-effect { flex: 1; margin: 0.8rem 0; color: var(--muted); }
.spell-card.locked { filter: grayscale(0.7); opacity: 0.55; }
.empty-state { grid-column: 1 / -1; padding: 2rem; text-align: center; border: 1px dashed var(--line); border-radius: 18px; color: var(--muted); }
.delete-card-button { position: absolute; top: 0.8rem; right: 0.8rem; padding: 0.25rem 0.5rem; color: var(--muted); background: transparent; border-color: var(--line); }

.weapon-config-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
fieldset { display: grid; gap: 0.65rem; min-width: 0; border: 1px solid var(--line); border-radius: 16px; padding: 1rem; }
legend { color: var(--accent-2); font-weight: 900; padding: 0 0.4rem; }
.inventory-list { display: grid; gap: 0.55rem; }
.inventory-row { display: grid; grid-template-columns: minmax(0, 1fr) 80px 110px auto; gap: 0.55rem; align-items: center; padding: 0.6rem; border: 1px solid var(--line); border-radius: 13px; background: rgba(0,0,0,0.12); }
.inventory-row strong { display: block; }
.inventory-row small { color: var(--muted); }
.coin-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
.upload-label { display: block; margin-bottom: 0.75rem; padding: 0.75rem; border: 1px dashed var(--line); border-radius: 13px; }

.stage-lights { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity 500ms ease; overflow: hidden; }
body[data-form="idol"] .stage-lights { opacity: 1; }
.stage-lights::before, .stage-lights::after { content: ""; position: absolute; top: -20vh; width: 30vw; height: 100vh; filter: blur(35px); transform-origin: top center; animation: sweep 5s ease-in-out infinite alternate; }
.stage-lights::before { left: 12vw; background: linear-gradient(to bottom, rgba(255, 87, 206, 0.24), transparent 72%); transform: rotate(16deg); }
.stage-lights::after { right: 12vw; background: linear-gradient(to bottom, rgba(255, 230, 116, 0.18), transparent 72%); transform: rotate(-16deg); animation-delay: -2.5s; }
@keyframes sweep { to { transform: rotate(-10deg); } }

body[data-form="idol"] .go-live-card,
body[data-form="idol"] .banhammer-card {
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent-2) 45%, transparent), 0 24px 70px rgba(255, 81, 199, 0.18);
}

dialog { width: min(620px, calc(100vw - 2rem)); border: 1px solid var(--line); border-radius: 20px; padding: 0; color: var(--text); background: var(--surface); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0,0,0,0.72); backdrop-filter: blur(7px); }
dialog form { display: grid; gap: 0.85rem; padding: 1.2rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.55rem; }

@media (max-width: 1050px) {
  .stat-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .attribute-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .spell-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .app-header { align-items: flex-start; flex-direction: column; }
  .header-actions { justify-content: flex-start; }
  .tab-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); position: static; }
  .hero-grid, .dashboard-grid, .skills-layout, .inventory-layout, .weapon-config-grid { grid-template-columns: 1fr; }
  .identity-card { grid-template-columns: 120px minmax(0, 1fr); }
  .stat-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .attribute-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .skill-list, .spell-grid { grid-template-columns: 1fr; }
  .slot-row { grid-template-columns: 1fr; }
  .section-heading { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 480px) {
  .identity-card { grid-template-columns: 1fr; }
  .avatar-frame { width: min(220px, 100%); margin: 0 auto; }
  .stat-strip, .attribute-grid { grid-template-columns: 1fr 1fr; }
  .mini-grid { grid-template-columns: 1fr; }
  .weapon-stats { grid-template-columns: 1fr; }
  .inventory-row { grid-template-columns: 1fr 70px; }
  .inventory-row .item-weight { display: none; }
}

@media print {
  .header-actions, .tab-bar, button, .live-switch, dialog, .stage-lights { display: none !important; }
  body { background: #fff; color: #111; }
  main { max-width: none; padding: 0; }
  .tab-panel { display: block !important; break-after: page; }
  .card, .stat-box, .slot-card { box-shadow: none; color: #111; background: #fff; border-color: #aaa; }
  input, select, textarea { color: #111; background: #fff; border-color: #bbb; }
}
