:root {
  --bg: #101219;
  --card: #1c202b;
  --line: #2c3242;
  --text: #f2f4f8;
  --muted: #98a1b3;
  --accent: #ffb347;
  --accent2: #ff7a45;
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
html, body { height: 100%; }

body {
  margin: 0;
  background: radial-gradient(1200px 800px at 20% 0%, #1d2130, #101219 60%);
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input { font-family: inherit; }

.screen { min-height: 100dvh; display: flex; flex-direction: column; }
.screen.hidden { display: none !important; }
.center { align-items: center; justify-content: center; }
.pad { padding: 20px clamp(16px, 3vw, 40px); gap: 14px; }

/* ---------- Loading ---------- */
.loading { align-items: center; justify-content: center; gap: 18px; }
.load-logo { font-size: clamp(24px, 4vw, 36px); font-weight: 700; letter-spacing: .08em; }
.bar { width: min(420px, 72vw); height: 10px; border-radius: 99px; background: #232838; overflow: hidden; }
.bar .fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); animation: fillbar 1.5s ease forwards; }
@keyframes fillbar { to { width: 100%; } }
.tip { color: var(--muted); font-size: 15px; text-align: center; padding: 0 20px; }

/* ---------- Big button ---------- */
.big-btn {
  font-size: clamp(26px, 4.5vw, 44px);
  font-weight: 800;
  letter-spacing: .06em;
  color: #14161c;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  border-radius: 24px;
  padding: clamp(22px, 4vh, 40px) clamp(40px, 8vw, 90px);
  cursor: pointer;
  box-shadow: 0 0 0 6px rgba(255, 179, 71, .12), 0 18px 50px rgba(255, 138, 61, .35);
  transition: transform .12s ease, box-shadow .12s ease;
}
.big-btn:hover { transform: translateY(-2px); }
.big-btn:active { transform: scale(.97); }
.big-btn:disabled { opacity: .45; cursor: default; transform: none; box-shadow: none; }

/* ---------- Header ---------- */
.head h1 { margin: 0 0 4px; font-size: clamp(20px, 2.6vw, 30px); }
.sub { margin: 0; color: var(--muted); font-size: clamp(13px, 1.4vw, 16px); }

/* ---------- Add row ---------- */
.add-row { display: flex; gap: 10px; }
.add-row input {
  flex: 1; min-width: 0;
  background: #1b1f2a; border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 12px 14px; font-size: 16px;
}
.add-row input:focus { outline: none; border-color: var(--accent); }
.add-row button {
  background: #262c3a; color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 0 22px; font-size: 16px; font-weight: 700; cursor: pointer;
}
.add-row button:hover { border-color: var(--accent); }

/* ---------- Warning ---------- */
.warn {
  background: rgba(255, 196, 0, .12);
  border: 1px solid rgba(255, 196, 0, .4);
  color: #ffd76a;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 15px;
}

/* ---------- Grid ---------- */
.grid {
  flex: 1;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
  padding: 4px;
  align-content: start;
}
.tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
  min-height: 88px;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 16px;
  color: var(--text);
  font-size: clamp(15px, 1.6vw, 18px);
  font-weight: 600;
  cursor: pointer;
  padding: 10px 8px;
  text-align: center;
  transition: transform .1s, border-color .1s, background .1s;
}
.tile .num { font-size: 12px; color: var(--muted); font-weight: 600; }
.tile .nm { line-height: 1.2; word-break: break-all; }
.tile:hover { border-color: #3d465c; }
.tile.on {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-color: transparent;
  color: #14161c;
  transform: translateY(-1px);
}
.tile.on .num { color: rgba(20, 22, 28, .6); }

/* ---------- Footer bar ---------- */
.foot { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding-top: 6px; }
.foot span { color: var(--muted); font-size: 16px; }
.primary {
  font-size: 20px; font-weight: 700;
  padding: 14px 28px; border-radius: 14px; border: none; cursor: pointer;
  color: #14161c; background: linear-gradient(135deg, var(--accent), var(--accent2));
}
.primary:disabled { opacity: .4; cursor: default; }
.survey-foot { flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 15px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------- Draw screen ---------- */
#drawScreen {
  align-items: center;
  justify-content: flex-start;
  padding-top: clamp(12px, 3vh, 28px);
  gap: clamp(8px, 1.6vh, 16px);
}
.draw-title { font-size: clamp(18px, 2.4vw, 26px); margin: 0; text-align: center; }

/* Result banner above the pointer */
.slot {
  font-size: clamp(22px, 3.6vw, 40px);
  font-weight: 900;
  letter-spacing: .04em;
  min-height: 1.25em;
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  color: var(--accent);
  padding: 2px 8px;
  line-height: 1.15;
  max-width: 92vw;
  overflow-wrap: anywhere;
}

/* ---------- Wheel ---------- */
.wheel-stage {
  position: relative;
  width: min(42vh, 88vw, 440px);
  aspect-ratio: 1;
  flex: none;
  margin: 8px 0 4px;
}
.pointer {
  position: absolute;
  top: -28px;
  left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 18px solid transparent;
  border-right: 18px solid transparent;
  border-top: 32px solid #ff4d4d;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .55));
  z-index: 10;
  pointer-events: none;
}
.wheel {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: #1c202b;
  box-shadow:
    0 0 0 6px #2c3242,
    0 0 0 12px #1c202b,
    0 14px 40px rgba(0, 0, 0, .55);
  transform-origin: 50% 50%;
  will-change: transform;
}
.wheel .divider {
  position: absolute;
  left: 50%; top: 0;
  width: 2px;
  height: 50%;
  margin-left: -1px;
  background: rgba(0, 0, 0, .2);
  transform-origin: 0 100%;
  pointer-events: none;
}
.wheel .label {
  position: absolute;
  color: #14161c;
  font-weight: 800;
  white-space: nowrap;
  pointer-events: none;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .55);
  z-index: 2;
  letter-spacing: .02em;
}
.hub {
  position: absolute;
  top: 50%; left: 50%;
  width: 13%; height: 13%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #4a5364, #1c202b);
  box-shadow: 0 0 0 4px #2c3242, 0 6px 18px rgba(0, 0, 0, .7);
  z-index: 5;
  pointer-events: none;
}
.wheel .empty-note {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  font-size: 22px;
  font-weight: 700;
}

/* Big button on draw screen — a bit smaller to leave room for the wheel */
#drawScreen .big-btn {
  font-size: clamp(20px, 3vw, 32px);
  padding: clamp(12px, 2vh, 20px) clamp(30px, 5vw, 64px);
  border-radius: 18px;
  flex: none;
}

/* Results */
.results {
  width: min(720px, 92vw);
  max-height: 18vh;
  overflow: auto;
  display: flex; flex-direction: column; gap: 8px;
  margin: 4px 0;
}
.res {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 14px; font-size: 20px;
}
.res .ri {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  background: var(--accent); color: #14161c;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px;
}
.res .rt { color: var(--muted); font-size: 14px; flex: none; }
.res .rn { font-weight: 700; }

.draw-actions { display: flex; gap: 12px; }
.draw-actions button {
  font-size: 16px; padding: 10px 22px; border-radius: 12px;
  border: 1px solid var(--line); background: #1b1f2a; color: var(--text); cursor: pointer;
}
.draw-actions button:hover { border-color: var(--accent); }

/* No-repeat toggle */
.repeat-toggle {
  position: fixed; right: 18px; bottom: 18px; z-index: 50;
  font-size: 15px; padding: 10px 16px; border-radius: 99px;
  border: 1px solid var(--line); background: #1b1f2a; color: var(--text); cursor: pointer;
}
.repeat-toggle.off { color: var(--muted); border-style: dashed; }

/* Toast */
#toast {
  position: fixed; top: 20px; left: 50%;
  transform: translate(-50%, -20px);
  background: #2a3040; color: var(--text);
  padding: 10px 18px; border-radius: 12px; font-size: 15px;
  border: 1px solid var(--line);
  opacity: 0; pointer-events: none; transition: .2s; z-index: 100;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 404 */
.notfound { text-align: center; padding: 20px; }
.notfound h1 { font-size: clamp(72px, 16vw, 140px); margin: 0; color: var(--accent); line-height: 1; }
.notfound p { color: var(--muted); font-size: 18px; margin: 8px 0 0; }
.notfound a {
  display: inline-block; margin-top: 24px;
  color: #14161c; background: linear-gradient(135deg, var(--accent), var(--accent2));
  text-decoration: none; padding: 14px 28px; border-radius: 14px;
  font-size: 18px; font-weight: 700;
}

/* Maker editor */
.maker { min-height: 100dvh; padding: 24px clamp(16px, 3vw, 40px); }
.maker h1 { margin: 0 0 4px; }
.maker-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.maker-bar input {
  flex: 1; min-width: 200px;
  background: #1b1f2a; border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 12px 14px; font-size: 16px;
}
.maker-bar input:focus { outline: none; border-color: var(--accent); }
.maker table { width: 100%; border-collapse: collapse; margin-top: 18px; }
.maker th, .maker td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; }
.maker th { color: var(--muted); font-weight: 600; font-size: 14px; }
.maker .idcell { color: var(--muted); white-space: nowrap; }
.maker td input {
  width: 100%;
  background: #1b1f2a; border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 16px;
}
.maker td input:focus { outline: none; border-color: var(--accent); }
.maker .del {
  background: transparent; border: 1px solid #5a3030; color: #ff8f8f;
  border-radius: 8px; padding: 6px 12px; cursor: pointer;
}
.ghost {
  background: transparent; border: 1px solid var(--line); color: var(--text);
  border-radius: 14px; padding: 14px 22px; font-size: 16px; cursor: pointer;
}
.ghost:hover { border-color: var(--accent); }