:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --text: #1b1f27;
  --muted: #5b6372;
  --border: #dde1e8;
  --accent: #2557d6;
  --accent-ink: #ffffff;
  --accent-soft: #e8eefc;
  --good: #1a7f4b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #171b23;
    --surface-2: #1f2430;
    --text: #e8ebf1;
    --muted: #9aa3b2;
    --border: #2b3240;
    --accent: #7aa2ff;
    --accent-ink: #0b1020;
    --accent-soft: #1d2740;
    --good: #4cc38a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
a:hover { text-decoration: none; }
.wrap { max-width: 880px; margin: 0 auto; padding: 0 16px; }

/* Header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.site-header .wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; padding-top: 12px; padding-bottom: 12px; }
.logo { font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.logo-mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-size: .85rem; }
.site-nav { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .92rem; }
.site-nav a { color: var(--muted); text-decoration: none; }
.site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--accent); }

/* Page */
main { padding-top: 20px; padding-bottom: 48px; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); line-height: 1.2; margin: 0 0 8px; }
h2 { font-size: 1.35rem; margin: 32px 0 10px; }
h3 { font-size: 1.08rem; margin: 22px 0 6px; }
.lead { color: var(--muted); font-size: 1.05rem; margin: 0 0 20px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin: 0 0 20px;
}
.card h2:first-child, .card h3:first-child { margin-top: 0; }

/* Forms */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
label { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; font-weight: 600; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
input, select, button { font: inherit; }
input[type="number"], input[type="date"], input[type="time"], input[type="text"], select {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 40px; padding: 8px 16px;
  border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-ink);
  font-weight: 600; cursor: pointer;
}
.btn.secondary { background: transparent; color: var(--accent); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: .88rem; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tab { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 999px; padding: 6px 14px; cursor: pointer; font-weight: 600; font-size: .92rem; }
.tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
[hidden] { display: none !important; }

/* Results */
.result {
  margin-top: 18px;
  padding: 18px;
  border-radius: 10px;
  background: var(--accent-soft);
}
.result-label { font-size: .95rem; color: var(--muted); }
.result-big { font-size: clamp(1.4rem, 4.5vw, 2rem); font-weight: 750; line-height: 1.25; margin: 2px 0; overflow-wrap: anywhere; }
.result-sub { color: var(--muted); }
.result.hero { margin: 0 0 18px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin: 16px 0 0; }
.facts div { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.facts dt { font-size: .8rem; color: var(--muted); }
.facts dd { margin: 0; font-weight: 650; }
.note { font-size: .88rem; color: var(--muted); }

/* Tables */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: .82rem; color: var(--muted); font-weight: 650; }
.timecard td input { min-width: 96px; }
.timecard td.num, .timecard th.num { text-align: right; white-space: nowrap; }
.dur-row { display: grid; grid-template-columns: 64px repeat(4, minmax(56px, 1fr)) 40px; gap: 8px; align-items: end; margin-bottom: 8px; }
.icon-btn { min-height: 44px; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); border-radius: 8px; cursor: pointer; }

/* Content */
.content p, .content li { max-width: 72ch; }
.content code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.faq details { border-bottom: 1px solid var(--border); padding: 12px 0; }
.faq summary { cursor: pointer; font-weight: 650; }
.faq details p { margin: 8px 0 0; color: var(--text); }

.link-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 14px; padding: 0; list-style: none; font-size: .93rem; }
.tool-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.tool-card { display: block; text-decoration: none; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.tool-card:hover { border-color: var(--accent); }
.tool-card strong { display: block; color: var(--accent); margin-bottom: 4px; }
.tool-card span { color: var(--muted); font-size: .92rem; }

.sr-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Text tools */
textarea {
  width: 100%;
  min-height: 220px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  resize: vertical;
}
textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.big-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.big-stat { background: var(--accent-soft); border-radius: 10px; padding: 12px 16px; }
.big-stat b { display: block; font-size: clamp(1.6rem, 5vw, 2.2rem); line-height: 1.1; }
.big-stat span { color: var(--muted); font-size: .9rem; }
td.num, th.num { text-align: right; }
.limit { margin: 10px 0; }
.limit-row { display: flex; justify-content: space-between; gap: 10px; font-size: .9rem; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--good); border-radius: 99px; }
.limit.over .bar i { background: #d64545; }
.limit.over .limit-row span:last-child { color: #d64545; font-weight: 650; }

/* Wheel */
.wheel-layout { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.wheel-box { text-align: center; }
.wheel-box canvas { width: 100%; max-width: 460px; aspect-ratio: 1; cursor: pointer; display: block; margin: 0 auto; touch-action: manipulation; }
.winner { margin-top: 12px; }
.winner .result-big { min-height: 1.3em; }
.history { margin: 8px 0 0; padding-left: 20px; color: var(--muted); font-size: .92rem; }
.history li:first-child { color: var(--text); font-weight: 600; }
@media (max-width: 720px) { .wheel-layout { grid-template-columns: 1fr; } }

/* Random numbers & dice */
.rng-out { font-size: clamp(2.6rem, 12vw, 4.5rem); font-weight: 800; line-height: 1.1; overflow-wrap: anywhere; }
.rng-out.many { font-size: clamp(1.2rem, 4vw, 1.6rem); font-weight: 700; }
.pop { animation: pop .25s ease-out; }
@keyframes pop { from { transform: scale(.92); opacity: .4; } to { transform: none; opacity: 1; } }
.dice { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; min-height: 72px; margin: 6px 0 4px; }
.die { display: inline-grid; place-items: center; min-width: 64px; height: 64px; padding: 0 8px; border-radius: 12px; background: var(--surface); border: 2px solid var(--text); font-size: 1.8rem; font-weight: 800; }
.die.d6 { font-size: 3.6rem; line-height: 1; border: 0; background: none; min-width: 0; padding: 0; }
.rolling .die { animation: roll .35s ease-out; }
@keyframes roll { 0% { transform: rotate(-25deg) scale(.8); } 60% { transform: rotate(10deg) scale(1.05); } 100% { transform: none; } }
@media (prefers-reduced-motion: reduce) { .pop, .rolling .die { animation: none; } }
.home-section { margin-top: 28px; }
.home-section h2 { margin-top: 0; }

/* Footer */
.site-footer { border-top: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: .88rem; }
.site-footer .wrap { padding-top: 20px; padding-bottom: 28px; display: flex; flex-wrap: wrap; gap: 8px 20px; justify-content: space-between; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.site-footer a { color: var(--muted); }

@media (max-width: 720px) {
  .site-nav { flex-wrap: nowrap; overflow-x: auto; width: 100%; padding-bottom: 4px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .site-nav::-webkit-scrollbar { display: none; }
  .site-nav a { white-space: nowrap; }
}
@media (max-width: 560px) {
  .card { padding: 16px; }
  .dur-row { grid-template-columns: repeat(3, 1fr); padding-bottom: 8px; border-bottom: 1px dashed var(--border); }
}
