:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f6f4ef;
  color: #182321;
  --ink: #182321;
  --muted: #687370;
  --surface: #fffdf8;
  --line: #ddd8ce;
  --teal: #176d67;
  --teal-dark: #0f514d;
  --coral: #d8644c;
  --gold: #d9a441;
  --blue: #486fa8;
  --shadow: 0 16px 45px rgba(24, 35, 33, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(23, 109, 103, 0.08), transparent 330px),
    var(--background, #f6f4ef);
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 920px);
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 18px;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 96px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal-dark);
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(32px, 7vw, 56px);
  line-height: 1.02;
}

h2 {
  font-size: 17px;
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--teal-dark);
  box-shadow: var(--shadow);
  font-size: 20px;
}

.tabs {
  grid-column: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: #e8e1d4;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  gap: 4px;
}

.tab {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #53615e;
  font-weight: 750;
}

.tab.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 6px 16px rgba(24, 35, 33, 0.08);
}

.panel,
.history {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel {
  grid-column: 1;
  display: none;
  padding: 18px;
  min-height: 496px;
}

.panel.is-active {
  display: grid;
  gap: 16px;
  align-content: start;
}

.result-stage {
  min-height: 190px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  color: #fff;
  position: relative;
  overflow: hidden;
}

.result-stage::after {
  content: "";
  position: absolute;
  inset: auto -10% -38% -10%;
  height: 120px;
  background: rgba(255, 255, 255, 0.14);
  transform: rotate(-4deg);
}

.lot-stage {
  background: linear-gradient(135deg, var(--teal), #274f7a);
}

.dice-stage {
  background: linear-gradient(135deg, var(--coral), #9a4d7c);
}

.picker-stage {
  background: linear-gradient(135deg, var(--blue), #3f7d59);
}

.result-label {
  align-self: end;
  font-size: 14px;
  opacity: 0.86;
}

.result-stage strong {
  align-self: start;
  font-size: clamp(34px, 9vw, 76px);
  line-height: 1.05;
  letter-spacing: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  z-index: 1;
}

.primary-action,
.secondary-action {
  min-height: 52px;
  border-radius: 8px;
  border: 0;
  padding: 0 18px;
  font-weight: 850;
}

.primary-action {
  background: var(--teal);
  color: #fff;
}

.secondary-action {
  background: #efe8dc;
  color: var(--ink);
}

.action-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

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

.lot-chip {
  min-height: 50px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #f1eee6;
  color: #30413e;
  font-weight: 750;
}

.dice-controls {
  display: grid;
  grid-template-columns: 1fr 160px;
  gap: 12px;
}

.dice-controls label,
.option-editor {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
}

input[type="range"] {
  accent-color: var(--coral);
}

select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
  color: var(--ink);
}

select {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  min-height: 150px;
  padding: 12px;
  line-height: 1.6;
}

.dice-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 46px;
}

.die {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #f3e6d8;
  color: #6c2f24;
  font-weight: 900;
}

.history {
  grid-column: 2;
  grid-row: 3 / span 2;
  padding: 16px;
  min-height: 558px;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

#historyCount {
  min-width: 30px;
  height: 30px;
  border-radius: 999px;
  background: #e1eee9;
  display: grid;
  place-items: center;
  color: var(--teal-dark);
  font-weight: 850;
}

#historyList {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

#historyList li {
  border-radius: 8px;
  background: #f4f0e7;
  padding: 12px;
  display: grid;
  gap: 4px;
}

.history-type {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.history-value {
  font-weight: 850;
  overflow-wrap: anywhere;
}

.shake {
  animation: shake 420ms ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px) rotate(-1deg); }
  75% { transform: translateX(8px) rotate(1deg); }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 18px;
    grid-template-columns: 1fr;
  }

  .tabs,
  .panel,
  .history {
    grid-column: 1;
  }

  .history {
    grid-row: auto;
    min-height: 0;
  }

  .dice-controls,
  .action-row,
  .quick-grid {
    grid-template-columns: 1fr;
  }
}
