:root {
  --bg-top: #f6f0e5;
  --bg-bottom: #d7c0a4;
  --paper: rgba(255, 250, 241, 0.75);
  --paper-strong: rgba(255, 249, 239, 0.92);
  --ink: #1f2b2a;
  --muted: #5d675f;
  --accent: #d0612d;
  --accent-deep: #a74a22;
  --cool: #2b6d72;
  --cool-deep: #173942;
  --line: rgba(31, 43, 42, 0.12);
  --shadow: rgba(32, 20, 11, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI Variable", "Gill Sans", sans-serif;
  background:
    radial-gradient(circle at 10% 12%, rgba(214, 104, 43, 0.22), transparent 26%),
    radial-gradient(circle at 85% 10%, rgba(43, 109, 114, 0.2), transparent 24%),
    linear-gradient(145deg, var(--bg-top), var(--bg-bottom));
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    linear-gradient(rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.08)),
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.05) 0,
      rgba(255, 255, 255, 0.05) 1px,
      transparent 1px,
      transparent 28px
    );
  pointer-events: none;
  mix-blend-mode: soft-light;
}

.app-shell {
  width: min(1240px, calc(100% - 32px));
  margin: 24px auto;
  position: relative;
  z-index: 1;
}

.hero-panel {
  display: grid;
  grid-template-columns: 1.8fr 0.9fr;
  gap: 18px;
  align-items: stretch;
  margin-bottom: 18px;
}

.hero-copy,
.formula-card,
.control-panel,
.stage-panel {
  border: 1px solid rgba(255, 255, 255, 0.45);
  box-shadow: 0 18px 40px var(--shadow);
  backdrop-filter: blur(14px);
}

.hero-copy {
  padding: 26px 28px;
  border-radius: 28px;
  background: linear-gradient(150deg, rgba(255, 248, 237, 0.88), rgba(242, 229, 209, 0.62));
}

.eyebrow {
  margin: 0 0 12px;
  font-size: 0.76rem;
  letter-spacing: 0.28em;
  color: var(--cool);
  font-weight: 800;
}

h1 {
  margin: 0;
  font-family: "Palatino Linotype", "Book Antiqua", serif;
  font-size: clamp(2.3rem, 4vw, 4.4rem);
  line-height: 0.95;
  letter-spacing: 0.03em;
}

.intro {
  margin: 16px 0 0;
  /*max-width: 62ch;*/
  line-height: 1.7;
  color: var(--muted);
  font-size: 1.02rem;
}

.formula-card {
  border-radius: 28px;
  background:
    linear-gradient(165deg, rgba(21, 57, 66, 0.95), rgba(23, 57, 66, 0.72)),
    radial-gradient(circle at top right, rgba(244, 192, 110, 0.24), transparent 45%);
  color: #f8efe6;
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.formula-label,
.stage-note,
.muted {
  color: rgba(248, 239, 230, 0.78);
}

.formula-label {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.75rem;
}

.formula-value {
  display: block;
  margin-top: 10px;
  font-size: clamp(2rem, 4vw, 3.6rem);
  line-height: 1;
}

.formula-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 18px;
  margin-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 1.05rem;
}

.formula-total strong {
  font-size: clamp(1.8rem, 3vw, 2.5rem);
}

.workspace {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 18px;
}

.control-panel {
  padding: 22px;
  border-radius: 28px;
  background: linear-gradient(180deg, var(--paper-strong), rgba(248, 238, 223, 0.78));
}

.panel-block + .panel-block {
  margin-top: 18px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
  font-weight: 800;
}

.muted {
  font-size: 0.82rem;
  color: var(--muted);
}

.count-badge {
  min-width: 2.1rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: rgba(43, 109, 114, 0.12);
  text-align: center;
  color: var(--cool-deep);
}

.stepper {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 56px;
  gap: 10px;
}

.stepper-button,
.count-input,
.side-button,
.roll-button {
  border: 1px solid transparent;
  border-radius: 18px;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease, background 160ms ease;
}

.stepper-button {
  min-height: 54px;
  background: linear-gradient(180deg, rgba(43, 109, 114, 0.12), rgba(43, 109, 114, 0.05));
  color: var(--cool-deep);
  font-size: 1.6rem;
  font-weight: 700;
  cursor: pointer;
}

.count-input {
  width: 100%;
  min-height: 54px;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.6);
  color: var(--ink);
  border-color: var(--line);
  text-align: center;
  font-size: 1.3rem;
  font-weight: 800;
}

.count-input:focus,
.stepper-button:focus,
.side-button:focus,
.roll-button:focus,
.count-range:focus {
  outline: 2px solid rgba(208, 97, 45, 0.35);
  outline-offset: 2px;
}

.count-range {
  width: 100%;
  margin-top: 14px;
  accent-color: var(--accent);
}

.dice-type-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.side-button {
  min-height: 64px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.5);
  border-color: var(--line);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--ink);
}

.side-button small {
  font-size: 0.76rem;
  color: var(--muted);
}

.side-button.is-active {
  background: linear-gradient(180deg, rgba(208, 97, 45, 0.18), rgba(208, 97, 45, 0.08));
  border-color: rgba(208, 97, 45, 0.38);
  box-shadow: inset 0 0 0 1px rgba(208, 97, 45, 0.14);
}

.roll-button {
  width: 100%;
  min-height: 62px;
  margin-top: 18px;
  background:
    linear-gradient(160deg, rgba(208, 97, 45, 0.95), rgba(167, 74, 34, 0.98)),
    radial-gradient(circle at top left, rgba(255, 218, 156, 0.28), transparent 40%);
  color: #fff7f0;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  cursor: pointer;
  text-transform: uppercase;
  box-shadow: 0 16px 32px rgba(167, 74, 34, 0.24);
}

.roll-button.is-rolling {
  background:
    linear-gradient(160deg, rgba(43, 109, 114, 0.95), rgba(23, 57, 66, 0.98)),
    radial-gradient(circle at top left, rgba(255, 218, 156, 0.18), transparent 40%);
}

.stepper-button:hover,
.side-button:hover,
.roll-button:hover {
  transform: translateY(-1px);
}

.hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.result-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 34px;
}

.result-chip,
.placeholder-chip {
  border-radius: 999px;
  padding: 0.48rem 0.8rem;
  font-weight: 700;
  font-size: 0.92rem;
}

.result-chip {
  background: rgba(43, 109, 114, 0.12);
  color: var(--cool-deep);
}

.placeholder-chip {
  background: rgba(31, 43, 42, 0.07);
  color: var(--muted);
}

.history-list {
  margin: 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.history-list li {
  line-height: 1.45;
  padding-right: 6px;
}

.stage-panel {
  position: relative;
  min-height: 680px;
  overflow: hidden;
  border-radius: 34px;
  padding: 18px;
  background:
    radial-gradient(circle at 50% 18%, rgba(245, 197, 126, 0.12), transparent 24%),
    radial-gradient(circle at bottom center, rgba(18, 57, 66, 0.65), rgba(13, 29, 34, 0.98) 72%);
}

.stage-panel::before,
.stage-panel::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}

.stage-panel::before {
  width: 440px;
  height: 440px;
  top: -180px;
  right: -110px;
  background: radial-gradient(circle, rgba(216, 116, 63, 0.22), transparent 70%);
}

.stage-panel::after {
  width: 520px;
  height: 520px;
  left: 50%;
  bottom: -360px;
  transform: translateX(-50%);
  background: radial-gradient(circle, rgba(255, 210, 145, 0.1), transparent 70%);
}

.stage-topline {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.stage-caption {
  color: rgba(255, 247, 236, 0.92);
  font-weight: 800;
  letter-spacing: 0.06em;
}

.stage-note {
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

#dice-canvas {
  display: block;
  width: 100%;
  height: calc(100% - 44px);
  min-height: 620px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0));
}

@media (max-width: 1080px) {
  .hero-panel,
  .workspace {
    grid-template-columns: 1fr;
  }

  .stage-panel {
    min-height: 560px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 20px, 1240px);
    margin: 10px auto 20px;
  }

  .hero-copy,
  .formula-card,
  .control-panel,
  .stage-panel {
    border-radius: 24px;
  }

  .control-panel,
  .stage-panel {
    padding: 16px;
  }

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

  #dice-canvas {
    min-height: 500px;
  }
}
