:root {
  --page: #1b1528;
  --card: #221b32;
  --field: #1c1630;
  --border: #3a2f54;
  --purple: #b66dff;
  --violet: #7e5cff;
  --cyan: #00eaff;
  --text: #ffffff;
  --muted: #b9b3d0;
}

* { box-sizing: border-box; }
body { background: var(--page); color: var(--text); font-family: 'Inter', system-ui, Segoe UI, Roboto, Arial, sans-serif; margin: 0; padding: 0; }
.wrap { width: min(1100px, calc(100% - 32px)); margin: 0 auto; padding-bottom: 60px; }
.home-bar { display: flex; align-items: center; margin-top: 10px; }
.home-link { display: flex; align-items: center; text-decoration: none; color: #fff; font-weight: 600; }
.home-icon { width: 22px; height: 22px; margin-right: 6px; }
header { margin: 12px 0 18px; }
h1 { font-size: 1.8em; font-weight: 700; margin: 0 0 6px; }
h2 { font-size: 1.12rem; margin: 0 0 5px; }
.muted { color: var(--muted); font-size: .92em; line-height: 1.45; }
.card { background: var(--card); border-radius: 12px; padding: 18px; box-shadow: 0 0 10px rgba(255,255,255,.05); margin-bottom: 14px; }
.hidden { display: none !important; }

.setup-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
.unit { color: var(--muted); font-weight: 400; }
input[type="number"], select { width: 100%; background: var(--field); border: 1px solid var(--border); border-radius: 7px; color: #fff; padding: 9px 10px; font: inherit; outline: none; }
input[type="number"]:focus, select:focus { border-color: var(--purple); box-shadow: 0 0 0 2px rgba(182,109,255,.15); }
input[type="checkbox"] { accent-color: var(--purple); }

button { background: linear-gradient(135deg, var(--purple), var(--violet)); border: none; color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; transition: opacity .25s ease, transform .15s ease, box-shadow .25s ease; box-shadow: 0 0 8px rgba(182,109,255,.35); }
button:hover { opacity: .92; transform: translateY(-1px); box-shadow: 0 0 12px rgba(182,109,255,.55); }
button:active { transform: translateY(0); opacity: .86; }
.secondary-btn { background: #302642; box-shadow: none; min-width: 0; }
.secondary-btn:hover { box-shadow: 0 0 10px rgba(182,109,255,.25); }
.setup-actions { display: flex; align-items: center; gap: 14px; margin-top: 16px; }
.status-message.error, .random-message.error, .modal-hint.error { color: #ffaaa8; }

.random-card { display: grid; grid-template-columns: 1.25fr .75fr; gap: 20px; align-items: stretch; }
.difficulty-range { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: end; margin: 16px 0 10px; max-width: 440px; }
.range-dash { color: var(--muted); padding-bottom: 9px; }
.compact-field span { font-size: .88em; color: #ddd; }
.eligibility-options { display: flex; gap: 18px; flex-wrap: wrap; margin: 2px 0 16px; }
.check-row { display: flex; align-items: center; gap: 7px; color: #ddd; font-size: .9rem; cursor: pointer; }
.random-message { margin-top: 10px; min-height: 20px; }
.random-result { min-height: 150px; border: 1px solid var(--border); border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 18px; position: relative; overflow: hidden; background: var(--field); color: #111; }
.random-result::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at 50% 50%, rgba(255,255,255,.15), transparent 65%); pointer-events: none; }
.random-result.empty { opacity: .75; color: #fff; }
.result-kicker { font-size: .72rem; letter-spacing: .16em; opacity: .8; position: relative; }
.result-main { font-size: clamp(1.7rem, 4vw, 2.7rem); font-weight: 800; margin: 5px 0; position: relative; }
.result-difficulty { font-size: .92rem; position: relative; }

.grid-topline { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 8px; }
.grid-actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.save-message { min-height: 19px; margin-bottom: 8px; }
.legend-wrap { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.legend-label { font-size: .88rem; color: var(--muted); }
.legend { display: flex; gap: 4px; flex-wrap: wrap; }
.legend-chip { width: 31px; height: 23px; border-radius: 5px; display: grid; place-items: center; font-size: .72rem; font-weight: 800; color: #111; border: 1px solid rgba(255,255,255,.18); }
.grid-scroll { overflow-x: auto; padding: 3px 2px 12px; }
.blackout-grid { display: grid; grid-template-columns: 62px repeat(var(--cols), minmax(72px, 1fr)); gap: 5px; min-width: calc(68px + var(--cols) * 77px); align-items: stretch; }
.corner, .speed-header, .incline-header { display: grid; place-items: center; color: var(--muted); font-size: .78rem; font-weight: 700; }
.corner { line-height: 1.2; text-align: center; }
.speed-header { min-height: 36px; }
.incline-header { min-height: 60px; text-align: center; }

.grid-cell { min-height: 62px; border: 1px solid rgba(255,255,255,.18); border-radius: 8px; cursor: pointer; color: #111; position: relative; overflow: hidden; box-shadow: inset 0 -10px 20px rgba(0,0,0,.06); transition: transform .12s ease, filter .18s ease, opacity .18s ease, box-shadow .18s ease; user-select: none; }
.grid-cell:hover { transform: translateY(-1px); filter: brightness(1.08); box-shadow: 0 0 10px rgba(255,255,255,.2); }
.grid-cell .combo { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-size: .82rem; opacity: .75; }
.grid-cell .difficulty { position: absolute; top: 5px; right: 6px; font-size: .7rem; font-weight: 900; opacity: .8; }
.grid-cell .completion-mark { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.35rem; font-weight: 900; color: #fff; text-shadow: 0 1px 8px rgba(0,0,0,.75); pointer-events: none; }
.grid-cell.partial { filter: saturate(.5) brightness(.72); color: #fff; border-color: rgba(255,255,255,.34); }
.grid-cell.partial::after { content: ""; position: absolute; inset: 0; background: rgba(10,8,16,.25); pointer-events: none; }
.grid-cell.partial .completion-mark { z-index: 1; }
.grid-cell.completed { filter: saturate(.28) brightness(.55); color: #fff; border-color: rgba(255,255,255,.34); }
.grid-cell.completed::after { content: ""; position: absolute; inset: 0; background: rgba(10,8,16,.38); pointer-events: none; }
.grid-cell.completed .completion-mark { z-index: 1; font-size: 2rem; }
.grid-cell.outside-range { filter: saturate(.18) brightness(.34); opacity: .52; }
.grid-cell.outside-range:hover { filter: saturate(.28) brightness(.47); opacity: .7; }
.grid-cell.selected { outline: 3px solid var(--cyan); box-shadow: 0 0 16px rgba(0,234,255,.85); z-index: 2; opacity: 1; }
.axis-note { margin-top: 2px; text-align: center; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(9,6,15,.72); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 20px; z-index: 100; }
.modal-card { width: min(430px, 100%); background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 20px; box-shadow: 0 18px 70px rgba(0,0,0,.55), 0 0 24px rgba(182,109,255,.12); }
.modal-combo { margin-bottom: 15px; }
.modal-hint { margin-top: 8px; min-height: 20px; }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #3d2c68; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #5e45a0; }
a { color: var(--purple); text-decoration: none; }
a:hover { text-decoration: underline; }

@media (max-width: 900px) {
  .setup-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }
}
@media (max-width: 800px) {
  .setup-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .random-card { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .wrap { width: min(100% - 20px, 1100px); }
  .setup-grid { grid-template-columns: 1fr 1fr; }
  .grid-topline { align-items: flex-start; flex-direction: column; }
  .grid-actions { justify-content: flex-start; }
  .difficulty-range { grid-template-columns: 1fr auto 1fr; }
}
