/* ===================================================================
   Dice Roller — earth87human (cream surface, tomato accent)
   Zero dependencies. Pure CSS.
   =================================================================== */

/* ============ Design tokens ============ */
:root {
  --bg: #faf6f1; --bg-2: #f3eee5; --surface: #ffffff; --surface-2: #faf6ed;
  --surface-3: #eee7d8; --border: #e8dfcc; --border-soft: #f0e9da;
  --text: #1f1a14; --text-2: #5c5547; --text-3: #6e6557; --text-faint: #b5ac9b;
  --accent: #e85f4d; --accent-2: #d44a39;
  --accent-soft: rgba(232,95,77,0.10); --accent-glow: rgba(232,95,77,0.30);
  --success: #3a9d6f; --r-sm: 8px; --r-md: 12px; --r-xl: 20px; --r-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04); --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 24px 48px rgba(0,0,0,0.12);
  --transition: 200ms cubic-bezier(0.4,0,0.2,1);
  --transition-slow: 400ms cubic-bezier(0.4,0,0.2,1);
  --font-ui: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", "PingFang TC", "PingFang SC", "Hiragino Sans", "Noto Sans CJK", sans-serif;
  --font-mono: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

/* ============ Reset ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
html, body {
  font-family: var(--font-ui);
  background: radial-gradient(ellipse 80% 50% at 50% 0%, rgba(255, 235, 220, 0.55) 0%, transparent 70%), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1, "ss01" 1;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select { font-family: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-2); }
ul, ol { list-style: none; }
[hidden] { display: none !important; }

/* Skip link */
.skip-link {
  position: absolute;
  left: -9999px; top: 0;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  font-weight: 600;
  border-radius: 0 0 var(--r-sm) 0;
  z-index: 1000;
}
.skip-link:focus { left: 0; }

/* ============ App layout ============ */
.app {
  max-width: 600px;
  margin: 0 auto;
  padding: clamp(12px, 3vw, 24px) clamp(12px, 3vw, 24px) 80px;
}

/* ============ Top bar ============ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 4px 28px;
}
.brand {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--text-2);
}
.brand:hover { color: var(--accent); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-link {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-3);
  padding: 6px 10px;
  border-radius: var(--r-sm);
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}
@media (max-width: 380px) {
  .nav-link { font-size: 12px; padding: 4px 8px; }
}
.nav-link:hover { color: var(--accent); background: var(--surface-2); }

.lang-switcher {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 6px 28px 6px 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 12 12' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3 5l3 3 3-3' stroke='%237a7973' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 12px;
  transition: border-color var(--transition);
}
.lang-switcher:hover { border-color: var(--text-3); }
.lang-switcher:focus { outline: none; border-color: var(--accent); }

/* ============ Page title ============ */
.page-title {
  font-size: clamp(24px, 4vw, 32px);
  font-weight: 700;
  letter-spacing: -0.02em;
  text-align: center;
  margin-bottom: 6px;
}
.page-sub {
  text-align: center;
  font-size: 14px;
  color: var(--text-3);
  margin-bottom: 36px;
}

/* ============ Workspace ============ */
.workspace {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-bottom: 64px;
}

/* ============ Dice type selector ============ */
.dice-type-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
.dice-type-label {
  font-size: 13px;
  color: var(--text-3);
  font-weight: 500;
}
.dice-type-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}
.pill-btn {
  padding: 8px 18px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #ffffff 0%, #f6f0e2 100%);
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.9),
    0 1px 2px rgba(60,40,10,0.06);
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform 80ms ease-out, box-shadow var(--transition);
}
.pill-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: linear-gradient(180deg, #fff7f4 0%, #fde7e0 100%);
}
.pill-btn.pill-active {
  background: linear-gradient(180deg, #ee6e5d 0%, var(--accent-2) 100%);
  color: #fff;
  border-color: var(--accent-2);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.35),
    inset 0 -1px 0 rgba(0,0,0,0.08),
    0 2px 6px var(--accent-glow);
}
.pill-btn:active {
  transform: translateY(1px);
  box-shadow:
    inset 0 1px 3px rgba(60,40,10,0.18),
    0 0 0 rgba(0,0,0,0);
}

/* ============ Quantity ============ */
.qty-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.qty-label {
  font-size: 13px;
  color: var(--text-3);
  font-weight: 500;
}
.qty-controls {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
}
.qty-btn {
  width: 36px; height: 34px;
  background: linear-gradient(180deg, #ffffff 0%, #f1ead9 100%);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.9),
    inset 0 -1px 0 rgba(120,100,60,0.08);
  transition: background var(--transition), transform 80ms ease-out, box-shadow var(--transition);
}
.qty-btn:hover { background: linear-gradient(180deg, #fffaf0 0%, #ece4d1 100%); }
.qty-btn:active {
  transform: translateY(1px);
  box-shadow: inset 0 2px 4px rgba(60,40,10,0.18);
}
.qty-value {
  min-width: 36px;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--surface);
  line-height: 34px;
  padding: 0 8px;
}

/* ============ Canvas card ============ */
.canvas-card {
  background: linear-gradient(180deg, #fdfbf6 0%, #f5efe2 100%);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 22px 20px 16px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.85),
    inset 0 -1px 0 rgba(120,100,60,0.06),
    0 1px 2px rgba(60,40,10,0.04),
    0 10px 28px rgba(60,40,10,0.07);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.canvas-stage {
  position: relative;
  width: 100%;
  max-width: 540px;
  aspect-ratio: 540 / 260;
  min-height: 180px;
}
#dice-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: var(--r-sm);
  display: block;
}
.dice-shadow {
  position: absolute;
  left: 50%;
  bottom: 8%;
  width: 56%;
  height: 14px;
  transform: translateX(-50%) scaleX(1);
  background: radial-gradient(ellipse at center,
    rgba(60,40,10,0.32) 0%,
    rgba(60,40,10,0.18) 45%,
    rgba(60,40,10,0) 75%);
  filter: blur(8px);
  opacity: 0.36;
  pointer-events: none;
  z-index: 0;
  transition: transform 120ms linear, opacity 120ms linear;
}
.dice-result {
  font-size: 13px;
  color: var(--text-3);
  font-weight: 500;
  min-height: 20px;
  text-align: center;
  transition: color var(--transition);
}
.dice-result.is-rolled {
  color: var(--accent);
  font-weight: 700;
  font-size: 15px;
}

/* ============ Action row ============ */
.action-row {
  display: flex;
  justify-content: center;
}
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 36px;
  background: linear-gradient(180deg, #ee6e5d 0%, var(--accent-2) 100%);
  color: #fff;
  border-radius: var(--r-md);
  font-size: 16px;
  font-weight: 700;
  min-width: 160px;
  letter-spacing: 0.02em;
  transition: background var(--transition), transform 80ms ease-out, box-shadow var(--transition);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.4),
    inset 0 -1px 0 rgba(0,0,0,0.12),
    0 4px 12px var(--accent-glow),
    0 1px 2px rgba(0,0,0,0.08);
}
.btn-primary:hover {
  background: linear-gradient(180deg, #f07866 0%, #de5141 100%);
  transform: translateY(-1px);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.45),
    inset 0 -1px 0 rgba(0,0,0,0.12),
    0 6px 16px var(--accent-glow),
    0 1px 2px rgba(0,0,0,0.08);
}
.btn-primary:active {
  transform: translateY(1px);
  box-shadow:
    inset 0 2px 4px rgba(0,0,0,0.22),
    0 1px 2px var(--accent-glow);
}
.btn-primary.is-rolling {
  opacity: 0.78;
  pointer-events: none;
}

/* ============ Presets ============ */
.preset-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}
.preset-label {
  font-size: 12px;
  color: var(--text-3);
  font-weight: 500;
  margin-right: 4px;
}
.preset-pill {
  padding: 5px 14px;
  border-radius: var(--r-pill);
  background: linear-gradient(180deg, #ffffff 0%, #f5efe0 100%);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--border-soft);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.9),
    0 1px 2px rgba(60,40,10,0.05);
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform 80ms ease-out, box-shadow var(--transition);
}
.preset-pill:hover {
  background: linear-gradient(180deg, #fff5f1 0%, #fce0d6 100%);
  border-color: var(--accent);
  color: var(--accent);
}
.preset-pill:active {
  transform: translateY(1px);
  box-shadow: inset 0 1px 3px rgba(60,40,10,0.18);
}

/* ============ Result panel ============ */
.result-panel {
  background: linear-gradient(160deg, #ee6e5d 0%, var(--accent-2) 100%);
  border-radius: var(--r-xl);
  padding: 18px 22px 20px;
  color: #fff;
  text-align: center;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.22),
    inset 0 -1px 0 rgba(0,0,0,0.10),
    0 8px 24px var(--accent-glow);
  animation: result-in 320ms cubic-bezier(0.32, 0.72, 0, 1);
  contain: layout;
}
@keyframes result-in {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}
.result-header {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.78);
  margin-bottom: 12px;
}
.result-dice {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
  line-height: 1.2;
  margin-bottom: 8px;
  min-height: 36px;
}
.die-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  border-radius: 10px;
  background: rgba(255,255,255,0.18);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.35),
    inset 0 -1px 0 rgba(0,0,0,0.10);
}
.die-sep {
  color: rgba(255,255,255,0.55);
  font-size: 14px;
  font-weight: 600;
  margin: 0 2px;
}
.die-eq {
  color: rgba(255,255,255,0.45);
  font-size: 16px;
  font-weight: 600;
  margin: 0 4px 0 6px;
  padding-left: 8px;
  border-left: 1px solid rgba(255,255,255,0.28);
}
.result-total {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.7);
}
.result-total.is-multi::before {
  content: "TOTAL";
  display: block;
  margin-bottom: 2px;
}
.result-total .total-num {
  font-size: 36px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
  display: block;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 1px rgba(0,0,0,0.12);
}

/* ============ History ============ */
.history-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 20px 24px;
}
.history-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 12px;
}
.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  max-height: 300px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.history-list::-webkit-scrollbar { width: 5px; }
.history-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.history-empty {
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
  padding: 16px 0;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  border-radius: var(--r-pill);
  background: linear-gradient(180deg, #fdfaf3 0%, #f3ecdc 100%);
  border: 1px solid var(--border-soft);
  font-size: 13px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.8),
    0 1px 2px rgba(60,40,10,0.04);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.history-item:hover {
  border-color: var(--border);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.85),
    0 2px 6px rgba(60,40,10,0.06);
}
.history-item-desc {
  color: var(--text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  letter-spacing: 0.02em;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  color: var(--accent);
}
.history-item-rolls {
  flex: 1;
  color: var(--text-3);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: left;
  padding-left: 4px;
}
.history-item-total {
  color: var(--accent);
  font-weight: 700;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  min-width: 28px;
  text-align: right;
}

.btn-text {
  display: block;
  width: 100%;
  background: var(--surface-2);
  color: var(--text-2);
  padding: 8px 14px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition);
}
.btn-text:hover { background: var(--surface-3); color: var(--text); }

/* ============ Info / SEO section ============ */
.info {
  max-width: 600px;
  margin: 0 auto;
  padding: 24px 0;
  color: var(--text-2);
  line-height: 1.7;
}
.info h2 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  margin: 36px 0 12px;
}
.info h2:first-child { margin-top: 0; }
.info h3 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin: 20px 0 6px;
}
.info p { margin-bottom: 14px; font-size: 15px; }
.info ol {
  margin-bottom: 14px;
  padding-left: 0;
  counter-reset: step;
}
.info ol li {
  padding: 6px 0 6px 32px;
  position: relative;
  list-style: none;
  font-size: 15px;
}
.info ol li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 0; top: 8px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  line-height: 22px;
}

/* ============ Footer ============ */
.site-footer {
  margin-top: 64px;
  padding-top: 24px;
  border-top: 1px solid var(--border-soft);
  text-align: center;
  font-size: 13px;
  color: var(--text-3);
}
.site-footer-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 6px;
}
.site-footer a { color: var(--text-2); }
.site-footer a:hover { color: var(--accent); }
.site-footer .sub {
  font-size: 11px;
  color: var(--text-faint);
}

/* ============ Responsive ============ */
@media (max-width: 600px) {
  .app { padding: 8px 12px 60px; }
  .topbar { padding: 4px 0 20px; }
  .lang-switcher { padding: 4px 22px 4px 8px; font-size: 12px; max-width: 140px; }
  .page-title { margin-bottom: 4px; }
  .page-sub { margin-bottom: 24px; }
  .canvas-card { padding: 16px 12px 12px; }
  .pill-btn { padding: 6px 14px; font-size: 13px; }
  .info { padding: 16px 4px; }
  .info h2 { font-size: 20px; margin-top: 28px; }
  .die-chip { min-width: 30px; height: 30px; font-size: 16px; padding: 0 8px; }
  .result-total .total-num { font-size: 30px; }
}

@media (max-width: 420px) {
  .topbar-right .nav-link { display: none; }
  .topbar-right { gap: 6px; }
  .lang-switcher { max-width: 130px; }
}

/* ============ Reduced motion ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============ Focus visible ============ */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus:not(:focus-visible),
select:focus:not(:focus-visible),
input:focus:not(:focus-visible) { outline: none; }

/* High contrast support */
@media (prefers-contrast: more) {
  :root { --border: #555; --border-soft: #444; --text-3: #ccc; }
}
