/* Hallmark · pre-emit critique: P4 H4 E4 S4 R4 V4 */
:root {
  --color-ink: #171512;
  --color-muted: #6f665d;
  --color-paper: #f7f1e8;
  --color-panel: #fffaf1;
  --color-line: #dfd3c1;
  --color-accent: #1f7a72;
  --color-accent-strong: #135850;
  --color-warm: #d48a43;
  --color-shadow: rgba(44, 30, 16, 0.18);
  --font-main: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  overflow-x: clip;
}

body {
  margin: 0;
  font-family: var(--font-main);
  color: var(--color-ink);
  background:
    linear-gradient(90deg, rgba(23, 21, 18, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(23, 21, 18, 0.04) 1px, transparent 1px),
    var(--color-paper);
  background-size: 42px 42px;
}

button,
input,
select {
  font: inherit;
}

.app {
  width: min(1120px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 22px;
  align-items: center;
  padding: 32px 0;
}

.table,
.panel {
  border: 1px solid var(--color-line);
  background: color-mix(in srgb, var(--color-panel) 94%, white);
  box-shadow: 0 22px 60px var(--color-shadow);
  border-radius: var(--radius);
}

.table {
  min-height: 640px;
  padding: clamp(20px, 4vw, 42px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 28px;
}

.topbar,
.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--color-accent);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  max-width: 660px;
  font-size: clamp(2.25rem, 7vw, 5.9rem);
  line-height: 0.92;
}

h2 {
  font-size: 1.25rem;
}

.total-card {
  width: 112px;
  min-width: 112px;
  aspect-ratio: 1;
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  background: var(--color-ink);
  color: var(--color-panel);
  display: grid;
  place-items: center;
  text-align: center;
  box-shadow: inset 0 -10px 0 rgba(255, 255, 255, 0.07);
}

.total-card span {
  font-size: 0.75rem;
  color: rgba(255, 250, 241, 0.74);
}

.total-card strong {
  display: block;
  font-size: 2.6rem;
  line-height: 0.9;
}

.dice-stage {
  min-height: 230px;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: clamp(12px, 3vw, 22px);
  padding: 20px;
  border: 1px dashed var(--color-line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.38);
}

.die {
  --spin: 0deg;
  width: clamp(74px, 11vw, 112px);
  aspect-ratio: 1;
  border: 2px solid var(--color-ink);
  border-radius: 18px;
  background: linear-gradient(145deg, #fffdf8, #eadcc7);
  color: var(--color-ink);
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: clamp(2rem, 5vw, 4rem);
  box-shadow: 8px 9px 0 var(--color-ink);
  transform: rotate(var(--spin));
  transition: transform 420ms cubic-bezier(0.16, 1, 0.3, 1);
}

.die.rolling {
  animation: tumble 520ms cubic-bezier(0.19, 1, 0.22, 1);
}

@keyframes tumble {
  0% {
    transform: translateY(0) rotate(0deg) scale(1);
  }
  45% {
    transform: translateY(-22px) rotate(18deg) scale(1.04);
  }
  100% {
    transform: translateY(0) rotate(var(--spin)) scale(1);
  }
}

.controls {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) 140px auto auto;
  gap: 12px;
  align-items: end;
}

label {
  display: grid;
  gap: 8px;
  color: var(--color-muted);
  font-weight: 750;
  font-size: 0.86rem;
}

label span {
  color: var(--color-ink);
}

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

select,
button {
  height: 46px;
  border: 1px solid var(--color-ink);
  border-radius: var(--radius);
}

select {
  padding: 0 12px;
  background: var(--color-panel);
  color: var(--color-ink);
}

button {
  padding: 0 18px;
  cursor: pointer;
  font-weight: 850;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--color-accent) 52%, white);
  outline-offset: 3px;
}

button:active {
  transform: translateY(2px);
}

.primary {
  background: var(--color-accent);
  color: white;
  box-shadow: 4px 5px 0 var(--color-ink);
}

.primary:hover {
  background: var(--color-accent-strong);
}

.secondary {
  background: var(--color-warm);
  color: var(--color-ink);
  box-shadow: 4px 5px 0 var(--color-ink);
}

.secondary:hover {
  background: color-mix(in srgb, var(--color-warm) 86%, white);
}

.panel {
  max-height: 640px;
  min-height: 640px;
  padding: 22px;
  overflow: hidden;
}

.panel-header {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--color-line);
}

.panel-header span {
  color: var(--color-muted);
  font-weight: 800;
  white-space: nowrap;
}

.history {
  display: grid;
  gap: 10px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}

.history li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.48);
}

.history strong {
  color: var(--color-accent-strong);
}

.history span {
  color: var(--color-muted);
  font-size: 0.88rem;
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .table,
  .panel {
    min-height: auto;
  }

  .panel {
    max-height: none;
  }
}

@media (max-width: 560px) {
  .app {
    width: min(100vw - 20px, 1120px);
    padding: 10px 0;
  }

  .topbar,
  .panel-header {
    align-items: stretch;
  }

  .topbar {
    flex-direction: column;
  }

  .total-card {
    width: 100%;
    min-width: 0;
    aspect-ratio: auto;
    min-height: 92px;
  }

  .dice-stage {
    min-height: 196px;
    padding: 14px;
  }

  .controls {
    grid-template-columns: 1fr 1fr;
  }

  .controls label:first-child {
    grid-column: 1 / -1;
  }

  button {
    padding: 0 10px;
  }
}
