/* =========================================================
   Random Number Generator — design tokens
   Aesthetic: luxury tech / glassmorphism. Deep space-navy
   backdrop, violet-to-gold gradient signature, frosted glass
   cards. The generated number is the hero of the page.
   ========================================================= */
:root {
  --bg-0: #0c0e1a;
  --bg-1: #12152a;
  --bg-2: radial-gradient(1200px 600px at 15% -10%, rgba(124,92,255,.22), transparent 60%),
           radial-gradient(1000px 500px at 105% 10%, rgba(255,184,92,.14), transparent 55%);
  --glass: rgba(255,255,255,.05);
  --glass-strong: rgba(255,255,255,.08);
  --line: rgba(255,255,255,.10);
  --text-hi: #f3f2fa;
  --text-mid: #b3b2c7;
  --text-low: #7d7c95;

  --violet: #8b6cff;
  --violet-2: #b98bff;
  --gold: #ffb85c;
  --mint: #5cf0c2;
  --coral: #ff7a7a;

  --radius-lg: 20px;
  --radius: 14px;
  --radius-sm: 9px;
  --font-display: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --shadow-card: 0 1px 0 rgba(255,255,255,.06) inset, 0 20px 50px rgba(0,0,0,.4);
  --transition: 180ms cubic-bezier(.4,0,.2,1);
}

[data-theme="light"] {
  --bg-0: #f5f3fb;
  --bg-1: #ffffff;
  --bg-2: radial-gradient(1200px 600px at 15% -10%, rgba(139,108,255,.14), transparent 60%),
           radial-gradient(1000px 500px at 105% 10%, rgba(255,184,92,.16), transparent 55%);
  --glass: rgba(20,16,50,.03);
  --glass-strong: rgba(20,16,50,.05);
  --line: rgba(20,16,50,.10);
  --text-hi: #1a1730;
  --text-mid: #524f6e;
  --text-low: #82809a;
  --shadow-card: 0 1px 0 rgba(255,255,255,.6) inset, 0 20px 40px rgba(30,20,60,.10);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background-color: var(--bg-0);
  background-image: var(--bg-2);
  background-attachment: fixed;
  color: var(--text-hi);
  font-family: var(--font-ui);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1160px; margin: 0 auto; padding: 0 20px; }

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--gold); color: #241804; padding: 10px 16px;
  border-radius: 0 0 8px 0; font-weight: 700; text-decoration: none;
}
.skip-link:focus { left: 0; }

:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 6px; }

a { color: var(--violet-2); }
.muted { color: var(--text-low); font-size: .85rem; }

/* ---------- header ---------- */
.site-header { border-bottom: 1px solid var(--line); backdrop-filter: blur(14px); position: sticky; top: 0; z-index: 20; background: rgba(12,14,26,.55); }
[data-theme="light"] .site-header { background: rgba(255,255,255,.65); }
.header-inner { display: flex; align-items: center; gap: 20px; padding: 14px 20px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text-hi); font-weight: 700; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--violet), var(--gold)); color: #14102c;
}
.brand-mark svg { fill: currentColor; }
.breadcrumb { flex: 1; overflow: hidden; }
.breadcrumb ol { display: flex; list-style: none; margin: 0; padding: 0; gap: 6px; font-size: .85rem; color: var(--text-low); white-space: nowrap; }
.breadcrumb li:not(:last-child)::after { content: "/"; margin-left: 6px; color: var(--text-low); }
.breadcrumb a { color: var(--text-mid); text-decoration: none; }
.breadcrumb a:hover { color: var(--gold); }

.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--glass); color: var(--text-hi); cursor: pointer; flex-shrink: 0;
  transition: border-color var(--transition), background var(--transition);
}
.theme-toggle:hover { border-color: var(--gold); }
.theme-toggle .icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .icon-sun { display: none; }
[data-theme="light"] .theme-toggle .icon-moon { display: none; }
[data-theme="light"] .theme-toggle .icon-sun { display: block; }

/* ---------- hero ---------- */
.hero { padding: 52px 20px 30px; text-align: center; }
.hero h1 {
  font-family: var(--font-display); font-size: clamp(2.1rem, 4.4vw, 3.1rem); margin: 0 0 12px; font-weight: 700;
  background: linear-gradient(100deg, var(--gold), var(--violet-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-sub { color: var(--text-mid); max-width: 620px; margin: 0 auto; font-size: 1.02rem; }

/* ---------- glass panel base ---------- */
.panel {
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow-card);
}

/* ---------- tool layout ---------- */
.tool { padding: 10px 20px 40px; }
.tool-grid { display: grid; grid-template-columns: 380px 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .tool-grid { grid-template-columns: 1fr; } }

.controls-panel { padding: 24px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: .82rem; color: var(--text-mid); margin-bottom: 6px; font-weight: 600; }
.field input[type="number"] {
  width: 100%; background: var(--glass-strong); border: 1px solid var(--line); border-radius: var(--radius-sm);
  color: var(--text-hi); font-family: var(--font-mono); font-size: 1rem; padding: 10px 12px; outline: none;
  transition: border-color var(--transition);
}
.field input[type="number"]:focus { border-color: var(--violet-2); }

.option-fieldset { border: none; padding: 0; margin: 0 0 16px; }
.option-fieldset legend { font-size: .82rem; color: var(--text-mid); font-weight: 600; margin-bottom: 8px; padding: 0; }
.segmented { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg-btn {
  font-size: .82rem; font-weight: 600; padding: 9px 4px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--glass-strong); color: var(--text-mid); cursor: pointer; transition: all var(--transition);
}
.seg-btn:hover { color: var(--text-hi); border-color: var(--violet-2); }
.seg-btn.is-active { background: linear-gradient(135deg, var(--violet), var(--violet-2)); color: #fff; border-color: transparent; }

.toggle-row { display: flex; flex-direction: column; gap: 12px; margin: 6px 0 20px; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: .88rem; color: var(--text-mid); position: relative; }
.switch input { position: absolute; opacity: 0; width: 40px; height: 22px; margin: 0; cursor: pointer; }
.switch-track {
  width: 40px; height: 22px; border-radius: 999px; background: var(--glass-strong); border: 1px solid var(--line);
  position: relative; flex-shrink: 0; transition: background var(--transition);
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--text-low); transition: transform var(--transition), background var(--transition);
}
.switch input:checked + .switch-track { background: linear-gradient(135deg, var(--violet), var(--gold)); border-color: transparent; }
.switch input:checked + .switch-track::after { transform: translateX(18px); background: #fff; }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--gold); outline-offset: 2px; }

.generate-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px;
  background: linear-gradient(135deg, var(--violet), var(--violet-2) 55%, var(--gold));
  color: #fff; border: none; border-radius: var(--radius); padding: 15px 18px; font-size: 1rem; font-weight: 700;
  cursor: pointer; transition: transform var(--transition), box-shadow var(--transition);
  box-shadow: 0 10px 30px rgba(139,108,255,.35);
}
.generate-btn:hover { transform: translateY(-1px); box-shadow: 0 14px 36px rgba(139,108,255,.45); }
.generate-btn:active { transform: translateY(0); }
.generate-btn .icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.generate-btn kbd {
  font-family: var(--font-mono); font-size: .72rem; background: rgba(255,255,255,.18); padding: 2px 6px; border-radius: 4px; margin-left: auto;
}

.quick-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.ghost-btn {
  flex: 1 1 auto; background: var(--glass-strong); border: 1px solid var(--line); color: var(--text-mid);
  border-radius: var(--radius-sm); padding: 9px 10px; font-size: .82rem; font-weight: 600; cursor: pointer; transition: all var(--transition);
}
.ghost-btn:hover { color: var(--text-hi); border-color: var(--gold); }

/* ---------- result panel ---------- */
.result-panel { padding: 24px; display: flex; flex-direction: column; gap: 18px; }
.result-stage {
  min-height: 200px; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 14px;
  padding: 20px; border-radius: var(--radius); background: var(--glass-strong); border: 1px solid var(--line);
}
.result-placeholder { color: var(--text-low); font-size: .95rem; }
.result-number {
  font-family: var(--font-display); font-weight: 700; font-size: clamp(2.4rem, 6vw, 3.6rem);
  background: linear-gradient(120deg, var(--gold), var(--violet-2)); -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: pop-in 340ms cubic-bezier(.2,.9,.3,1.3);
}
.result-chip {
  font-family: var(--font-mono); font-size: 1.3rem; font-weight: 600; background: var(--glass); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px 16px; color: var(--text-hi); animation: pop-in 300ms cubic-bezier(.2,.9,.3,1.3);
}
@keyframes pop-in { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .result-number, .result-chip { animation: none; } }

.result-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.icon-text-btn {
  display: inline-flex; align-items: center; gap: 8px; background: var(--glass-strong); border: 1px solid var(--line);
  color: var(--text-mid); border-radius: var(--radius-sm); padding: 9px 14px; font-size: .85rem; font-weight: 600;
  cursor: pointer; transition: all var(--transition);
}
.icon-text-btn:hover { color: var(--text-hi); border-color: var(--violet-2); }
.icon-text-btn .icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 560px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
  background: var(--glass-strong); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px;
  display: flex; flex-direction: column; gap: 4px; text-align: center;
}
.stat-label { font-size: .72rem; color: var(--text-low); text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-family: var(--font-mono); font-size: 1.15rem; font-weight: 700; color: var(--gold); }

/* ---------- history ---------- */
.history-panel { margin-top: 20px; padding: 20px 24px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.panel-head h2 { font-size: .95rem; text-transform: uppercase; letter-spacing: .05em; margin: 0; color: var(--text-mid); }
.history-list { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.history-item {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  font-family: var(--font-mono); font-size: .85rem; padding: 9px 12px; border-radius: var(--radius-sm);
  background: var(--glass-strong); border: 1px solid var(--line);
}
.history-item .h-values { color: var(--text-hi); overflow-wrap: anywhere; }
.history-item .h-time { color: var(--text-low); font-size: .74rem; white-space: nowrap; }

/* ---------- toasts ---------- */
.toast-region { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 60; }
.toast {
  background: var(--bg-1); border: 1px solid var(--line); color: var(--text-hi); padding: 12px 16px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card); font-size: .88rem; animation: toast-in 220ms ease-out;
  border-left: 3px solid var(--mint);
}
.toast.is-error { border-left-color: var(--coral); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- guide article ---------- */
.guide { padding: 40px 20px 80px; border-top: 1px solid var(--line); }
.guide h2 { font-size: 1.5rem; margin-top: 2.4em; scroll-margin-top: 80px; font-family: var(--font-display); }
.guide h2:first-of-type { margin-top: 0; }
.guide h3 { font-size: 1.08rem; color: var(--text-hi); scroll-margin-top: 80px; }
.guide p { color: var(--text-mid); max-width: 74ch; }
.guide code { font-family: var(--font-mono); background: var(--glass-strong); border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; color: var(--gold); font-size: .9em; }
.guide ul { color: var(--text-mid); max-width: 74ch; }
.guide .checklist { list-style: none; padding-left: 0; }
.guide .checklist li { padding: 4px 0; }

.toc { padding: 18px 22px; margin-bottom: 30px; }
.toc h2 { margin-top: 0 !important; font-size: 1rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-mid); font-family: var(--font-ui); }
.toc ol { columns: 2; column-gap: 30px; padding-left: 18px; margin: 0; }
@media (max-width: 640px) { .toc ol { columns: 1; } }
.toc a { text-decoration: none; color: var(--text-mid); font-size: .92rem; }
.toc a:hover { color: var(--gold); }

.content-table { width: 100%; border-collapse: collapse; margin: 14px 0 24px; font-size: .92rem; }
.content-table caption { text-align: left; color: var(--text-low); font-size: .8rem; margin-bottom: 6px; }
.content-table th, .content-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); color: var(--text-mid); }
.content-table th { color: var(--text-hi); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }

.use-case-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 16px 0 26px; }
@media (max-width: 860px) { .use-case-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .use-case-grid { grid-template-columns: 1fr; } }
.use-case { background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.use-case h3 { margin: 0 0 6px; font-size: .95rem; }
.use-case p { margin: 0; font-size: .88rem; }

.faq h3 { margin-bottom: 4px; }
.faq p { margin-top: 0; }

/* ---------- footer ---------- */
.site-footer { border-top: 1px solid var(--line); padding: 24px 0; }
.site-footer p { color: var(--text-low); font-size: .85rem; text-align: center; margin: 0; }

/* ---------- print ---------- */
@media print {
  .site-header, .site-footer, .controls-panel, .result-actions, .history-panel, .guide, .toast-region, .hero-sub { display: none !important; }
  body { background: #fff; color: #000; }
  .result-number, .result-chip { color: #000 !important; -webkit-text-fill-color: #000; }
}

/* ---------- responsive tweaks ---------- */
@media (max-width: 520px) {
  .header-inner { gap: 10px; }
  .breadcrumb { display: none; }
  .hero { padding: 34px 16px 18px; }
  .field-row { grid-template-columns: 1fr 1fr; }
}
