:root {
  --bg: #f2efe7;
  --card: #ffffff;
  --edge: #3d3a33;
  --face: #faf6ea;
  --pip: #2b2620;
  --ok: #1e7e46;
  --ok-dark: #14532d;
  --warn: #b26a00;
  --muted: #9a938a;
  --line: #d8d4c8;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: #333;
  padding:
    calc(env(safe-area-inset-top) + 6px)
    calc(env(safe-area-inset-right) + 10px)
    calc(env(safe-area-inset-bottom) + 10px)
    calc(env(safe-area-inset-left) + 10px);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
}

h1 { font-size: 1.15rem; margin: 0; font-weight: 700; }

#sound-btn {
  font-size: 1.25rem;
  line-height: 1;
  background: none;
  border: none;
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
}

main {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 4px 6px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.controls {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sides {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 4px 8px;
}

.sides-label { font-size: 0.85rem; color: #777; }

.step-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 1.35rem;
  line-height: 1;
  color: #444;
  cursor: pointer;
  padding: 0;
  touch-action: none;
}

.step-btn:active { background: #ececec; }

#sides-value {
  min-width: 2.8em;
  text-align: center;
  font-weight: 700;
  font-size: 1.05rem;
}

.secondary {
  border: 1px solid var(--line);
  background: var(--card);
  color: #444;
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.secondary:active { background: #ececec; }

.step-btn:disabled, .secondary:disabled, #roll-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.die-wrap {
  width: min(80vw, 330px);
  aspect-ratio: 1 / 1;
  margin: 4px 0;
}

#die-svg { width: 100%; height: 100%; display: block; overflow: visible; }
#die-svg text { font-family: inherit; font-weight: 700; }

#status {
  margin: 0;
  min-height: 1.4em;
  text-align: center;
  font-size: 1rem;
  color: #555;
}

#status.ok   { color: var(--ok);   font-weight: 700; }
#status.warn { color: var(--warn); font-weight: 700; }

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  width: 100%;
}

.chip {
  min-width: 36px;
  padding: 5px 7px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--card);
  color: var(--muted);
  font-weight: 700;
  font-size: 0.95rem;
}

.chip.used { background: var(--ok); border-color: var(--ok); color: #fff; }
.chip.last { background: var(--ok-dark); border-color: var(--ok-dark); color: #fff; }

.actions { width: 100%; display: flex; gap: 10px; }

#roll-btn {
  flex: 1;
  padding: 16px;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #fff;
  background: var(--ok);
  border: none;
  border-radius: 18px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--ok-dark);
  transition: transform 0.05s;
}

#roll-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ok-dark);
}

.kbd-hint {
  display: none;
  font-size: 0.7rem;
  font-weight: 600;
  opacity: 0.85;
  letter-spacing: 0;
  margin-left: 8px;
  vertical-align: middle;
  text-transform: lowercase;
}

/* show the keyboard hint only on devices with a real pointer */
@media (hover: hover) and (pointer: fine) {
  .kbd-hint { display: inline; }
}

dialog {
  border: none;
  border-radius: 16px;
  padding: 22px;
  max-width: 320px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}

dialog::backdrop { background: rgba(0, 0, 0, 0.4); }

#complete-text { margin: 0; font-weight: 600; }

.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 16px;
}

.dialog-actions button {
  border: 1px solid var(--line);
  background: var(--card);
  color: #444;
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
}

.dialog-actions button.primary {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
  font-weight: 700;
}
