:root {
  color-scheme: dark;
  --bg: #14110f;
  --panel: rgba(35, 30, 26, 0.92);
  --panel-2: rgba(48, 42, 36, 0.96);
  --text: #fff7e8;
  --muted: #cdbfa9;
  --line: rgba(255, 244, 220, 0.13);
  --accent: #f0b84f;
  --accent-2: #8ed1b4;
  --danger: #ff8b8b;
  --shadow: rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(240, 184, 79, 0.16), transparent 30rem),
    radial-gradient(circle at 80% 10%, rgba(142, 209, 180, 0.12), transparent 28rem),
    var(--bg);
  color: var(--text);
}

.skip-link {
  position: fixed;
  left: 1rem;
  top: -100px;
  padding: .7rem 1rem;
  border-radius: 999px;
  background: var(--accent);
  color: #21170a;
  z-index: 10;
}
.skip-link:focus { top: 1rem; }

.app-shell { width: min(1160px, calc(100vw - 24px)); margin: 0 auto; padding: 24px 0 48px; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: linear-gradient(135deg, rgba(255,255,255,0.08), rgba(255,255,255,0.02));
  box-shadow: 0 18px 50px var(--shadow);
}
.eyebrow { margin: 0 0 .25rem; color: var(--accent-2); font-weight: 700; letter-spacing: .08em; font-size: .82rem; }
h1 { margin: 0; font-size: clamp(1.8rem, 4vw, 3.2rem); line-height: 1; }
h1 span { display: block; margin-top: .45rem; color: var(--muted); font-size: .95rem; font-weight: 600; }

.mode-switch { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }
button, input, select {
  font: inherit;
}
button {
  border: 0;
  border-radius: 14px;
  padding: .8rem 1rem;
  cursor: pointer;
  color: var(--text);
  background: rgba(255,255,255,.08);
  transition: transform .15s ease, background .15s ease, opacity .15s ease;
}
button:hover { transform: translateY(-1px); background: rgba(255,255,255,.13); }
button:active { transform: translateY(0); }
button:disabled { cursor: not-allowed; opacity: .5; transform: none; }
.mode-btn.active, .primary-btn { background: linear-gradient(135deg, var(--accent), #e4773d); color: #21170a; font-weight: 800; }
.secondary-btn { background: linear-gradient(135deg, #2f8f74, #58c49c); color: #071a14; font-weight: 800; }
.ghost-btn { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.ghost-btn.danger { color: var(--danger); }
.primary-btn { width: 100%; margin-top: 1rem; font-size: 1.05rem; }

.safety-banner {
  margin: 16px 0;
  padding: 14px 18px;
  border: 1px solid rgba(142, 209, 180, .35);
  border-radius: 18px;
  background: rgba(142, 209, 180, .08);
  color: #ddfff2;
}

.layout { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; }
.panel {
  grid-column: span 6;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: 0 18px 48px var(--shadow);
  padding: 18px;
}
.balance-panel, .developer-panel { grid-column: span 12; }
.history-panel, .settings-panel { grid-column: span 6; }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }
h2, h3 { margin: 0; }
.pill { display: inline-flex; align-items: center; border-radius: 999px; padding: .4rem .7rem; background: rgba(240, 184, 79, .15); color: #ffd889; font-size: .85rem; font-weight: 800; white-space: nowrap; }
.pill.quiet { background: rgba(255,255,255,.07); color: var(--muted); }

.currency-display { font-size: clamp(1.4rem, 3vw, 2.35rem); font-weight: 900; letter-spacing: -.04em; }
.mini-grid, .stats-grid, .settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .7rem;
  margin-top: 1rem;
}
.stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.mini-grid > div, .stats-grid > div {
  padding: .9rem;
  border-radius: 16px;
  background: rgba(255,255,255,.055);
  border: 1px solid var(--line);
}
.mini-grid span, .stats-grid span { display: block; color: var(--muted); font-size: .82rem; margin-bottom: .2rem; }
.mini-grid strong, .stats-grid strong { font-size: 1rem; }

.input-label { display: block; color: var(--muted); margin: .6rem 0 .35rem; font-weight: 700; }
input, select {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.25);
  color: var(--text);
  padding: .85rem .9rem;
  outline: none;
}
input:focus, select:focus, button:focus-visible { outline: 3px solid rgba(240,184,79,.45); outline-offset: 2px; }
.help-text { margin: .6rem 0; color: var(--muted); line-height: 1.65; }
.error-text { min-height: 1.4rem; color: var(--danger); font-weight: 800; }
.quick-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: .55rem; margin-top: .8rem; }
.tsumo-area {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 18px;
  background: rgba(0,0,0,.22);
  border: 1px solid var(--line);
}
.tsumo-area span { display: block; color: var(--muted); font-size: .85rem; margin-bottom: .15rem; }
.tsumo-stone {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: linear-gradient(135deg, #050505, #272727 55%, #070707);
  box-shadow: inset -10px -12px 25px rgba(0,0,0,.8), inset 8px 8px 20px rgba(255,255,255,.06), 0 10px 35px rgba(0,0,0,.55);
  transform: rotate(6deg);
}

.dice-row { display: flex; justify-content: center; gap: 1rem; margin: 1rem 0; }
.die {
  width: clamp(72px, 18vw, 110px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 24px;
  background: linear-gradient(135deg, #fff8eb, #cfc2ad);
  color: #1c1308;
  font-size: clamp(2rem, 8vw, 4rem);
  font-weight: 950;
  box-shadow: 0 15px 35px rgba(0,0,0,.35);
}
.die.rolling { animation: tumble .12s infinite linear; }
@keyframes tumble { 50% { transform: rotate(4deg) translateY(-5px); } }
.reduced-motion .die.rolling { animation: none; }

.result-card {
  padding: 1rem;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.06);
}
.result-card h3 { font-size: 1.8rem; margin: .2rem 0; }
.result-kicker { margin: 0; color: var(--muted); font-weight: 800; }
.result-card.win { border-color: rgba(142,209,180,.5); background: rgba(142,209,180,.1); }
.result-card.bigwin { border-color: rgba(240,184,79,.7); background: rgba(240,184,79,.13); box-shadow: 0 0 48px rgba(240,184,79,.12); }
.result-card.lose { border-color: rgba(255,139,139,.35); background: rgba(255,139,139,.08); }
.result-card.draw { border-color: rgba(255,255,255,.2); }
#net-display { display: block; margin-top: .75rem; font-size: 1.35rem; }

.history-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .6rem; }
.history-list li {
  padding: .75rem;
  border-radius: 14px;
  background: rgba(255,255,255,.055);
  border: 1px solid var(--line);
}
.history-list .meta { color: var(--muted); font-size: .85rem; margin-top: .25rem; }
.role-counts { display: grid; grid-template-columns: repeat(2, 1fr); gap: .45rem; padding-top: .8rem; }
.role-counts div { display: flex; justify-content: space-between; padding: .5rem .6rem; border-radius: 12px; background: rgba(255,255,255,.055); }

.dev-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.dev-box { border: 1px solid var(--line); background: rgba(255,255,255,.05); border-radius: 20px; padding: 1rem; }
.dice-selects { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; margin: .75rem 0; }
.code-output {
  white-space: pre-wrap;
  overflow: auto;
  max-height: 420px;
  background: rgba(0,0,0,.33);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem;
  color: #eafff4;
}

[data-theme="dark_stone"] { --bg: #060606; --panel: rgba(12,12,14,.94); --panel-2: rgba(22,22,24,.98); --accent: #b6b6b6; --accent-2: #6be6ff; }
[data-theme="paper_log"] { color-scheme: light; --bg: #efe2c6; --panel: rgba(255,249,235,.94); --panel-2: #fff9eb; --text: #2b2116; --muted: #6c5c46; --line: rgba(62,43,24,.16); --accent: #c07832; --accent-2: #2d8066; --shadow: rgba(87,58,29,.13); }
[data-theme="paper_log"] .die { background: #fffdf5; color: #2b2116; }
[data-theme="paper_log"] input, [data-theme="paper_log"] select { background: rgba(255,255,255,.6); color: var(--text); }

@media (max-width: 860px) {
  .topbar { align-items: stretch; flex-direction: column; }
  .mode-switch { justify-content: stretch; }
  .mode-switch button { flex: 1; }
  .panel, .balance-panel, .developer-panel, .history-panel, .settings-panel { grid-column: span 12; }
  .mini-grid, .stats-grid, .settings-grid, .dev-grid { grid-template-columns: 1fr; }
  .quick-buttons { grid-template-columns: repeat(2, 1fr); }
}
