:root {
  --bg: #0d1117;
  --bg2: #151b25;
  --card: #1a2230;
  --card2: #222c3d;
  --line: #2c3850;
  --text: #e8ecf3;
  --muted: #8d99ae;
  --moon: #f2d98a;
  --moon-d: #c9ae5c;
  --blood: #e5484d;
  --blood-bg: #3a1a1e;
  --vamp: #b07cff;
  --vamp-bg: #2a1f40;
  --green: #4cc38a;
  --love: #ff7aa8;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 80% -10%, #1d2a44 0%, transparent 60%), var(--bg);
  background-attachment: fixed;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--moon); }
code { background: var(--card2); padding: 1px 6px; border-radius: 6px; }

.loading { display: grid; place-items: center; height: 100vh; font-size: 56px; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.wrap { max-width: 640px; margin: 0 auto; padding: calc(12px + var(--safe-t)) 14px calc(110px + var(--safe-b)); }
.brand { font-family: Georgia, "Times New Roman", serif; font-size: 30px; margin: 14px 0 18px; letter-spacing: .5px; }
.brand span { display: block; font: 600 13px/1.2 system-ui, sans-serif; color: var(--muted); letter-spacing: 2px; text-transform: uppercase; margin-top: 4px; }
h2 { font-size: 20px; margin: 22px 0 10px; }
h3 { font-size: 16px; margin: 18px 0 8px; color: var(--moon); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-t)) 12px 8px;
  background: rgba(13,17,23,.88); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .title { flex: 1; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.icon-btn {
  min-width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); font-size: 20px; display: grid; place-items: center; cursor: pointer; padding: 0 10px;
}
.icon-btn:disabled { opacity: .35; }
.progress { height: 3px; background: var(--line); }
.progress > i { display: block; height: 100%; background: var(--moon); transition: width .3s; }

/* Cards & Buttons */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.card.tight { padding: 12px; }
.card.night { background: linear-gradient(160deg, #1b2440, #141a28); }
.card.blood { background: var(--blood-bg); border-color: #6b2a31; }
.card.vamp { background: var(--vamp-bg); border-color: #4f3a7a; }
.card.gold { border-color: var(--moon-d); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card2); font-weight: 600; cursor: pointer; text-decoration: none; color: var(--text);
}
.btn.block { display: flex; width: 100%; margin: 8px 0; }
.btn.primary { background: var(--moon); color: #1b1606; border-color: var(--moon); }
.btn.danger { background: var(--blood); border-color: var(--blood); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 14px; }
.btn:disabled { opacity: .4; cursor: default; }
.row { display: flex; gap: 8px; align-items: center; }
.row > .grow { flex: 1; }
.stack > * + * { margin-top: 8px; }

/* Fixed bottom action */
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 10px 14px calc(10px + var(--safe-b));
  background: linear-gradient(to top, rgba(13,17,23,1) 65%, rgba(13,17,23,0));
}
.bottom-bar .inner { max-width: 640px; margin: 0 auto; display: flex; gap: 8px; }
.bottom-bar .btn { flex: 1; min-height: 56px; font-size: 17px; }

/* Forms */
.form label { display: block; margin: 10px 0; font-size: 14px; color: var(--muted); }
.form input, .form select, .form textarea, input.field, textarea.field, select.field {
  display: block; width: 100%; margin-top: 4px; padding: 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg2); color: var(--text); font-size: 16px;
}
.form textarea, textarea.field { min-height: 110px; resize: vertical; }
.check { display: flex !important; align-items: center; gap: 10px; color: var(--text) !important; }
.check input { width: 22px !important; height: 22px; margin: 0 !important; accent-color: var(--moon); }
.alert { background: var(--blood-bg); border: 1px solid #6b2a31; color: #ffd0d3; padding: 12px; border-radius: 10px; margin: 10px 0; }
.warn { background: #3a3218; border: 1px solid #6e5d24; color: #f6e3a6; padding: 10px 12px; border-radius: 10px; margin: 8px 0; font-size: 14px; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 12px; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.tap { cursor: pointer; }

/* Player grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin: 10px 0; }
.pbtn {
  min-height: 56px; border-radius: 12px; border: 2px solid var(--line); background: var(--card2);
  padding: 8px 10px; font-weight: 600; text-align: left; cursor: pointer; position: relative; line-height: 1.2;
}
.pbtn small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; margin-top: 2px; }
.pbtn.sel { border-color: var(--moon); background: #3a3218; }
.pbtn.dead { opacity: .45; text-decoration: line-through; }
.pbtn.none { border-style: dashed; color: var(--muted); }
.pbtn .badge { position: absolute; top: 6px; right: 8px; font-size: 14px; }

/* Narration */
.narr {
  font-family: Georgia, "Times New Roman", serif; font-size: 20px; line-height: 1.5; color: var(--moon);
  padding: 4px 0;
}
.step-role { font-size: 13px; letter-spacing: 2px; text-transform: uppercase; color: var(--muted); }
.step-title { font-size: 26px; font-weight: 800; margin: 2px 0 10px; display: flex; align-items: center; gap: 10px; }
.reveal { font-size: 22px; font-weight: 800; text-align: center; padding: 16px; border-radius: 12px; background: #2f2a15; border: 1px solid var(--moon-d); color: var(--moon); }
.hint { font-size: 14px; color: var(--muted); }

/* Chips & tags */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; background: var(--card2); border: 1px solid var(--line); font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip.wolf { background: #3a1a1e; border-color: #6b2a31; color: #ffb3b7; }
.chip.vamp { background: var(--vamp-bg); border-color: #4f3a7a; color: #dcc6ff; }
.chip.dorf { background: #183026; border-color: #2c5a45; color: #b6f0d2; }
.chip.solo { background: #3a3218; border-color: #6e5d24; color: #f6e3a6; }
.chip.dead { background: transparent; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* Counter */
.counter { display: flex; align-items: center; gap: 6px; }
.counter button { width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--card2); font-size: 22px; cursor: pointer; }
.counter b { min-width: 26px; text-align: center; font-size: 18px; }

/* Timer */
.timer { text-align: center; }
.timer .time { font-size: 56px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: 1px; }
.timer.over .time { color: var(--blood); animation: pulse 1s infinite; }

/* Drag & drop */
.drag-handle { cursor: grab; touch-action: none; font-size: 22px; color: var(--muted); padding: 4px 8px; user-select: none; }
li.dragging { background: var(--card2); box-shadow: 0 8px 20px rgba(0,0,0,.5); position: relative; z-index: 5; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 18px 18px 0 0; width: 100%; max-width: 640px;
  max-height: 88vh; overflow: auto; padding: 16px 16px calc(16px + var(--safe-b));
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.modal h2 { margin-top: 4px; }
.tabs { display: flex; gap: 6px; margin: 6px 0 10px; }
.tabs button { flex: 1; min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-weight: 600; }
.tabs button.on { background: var(--moon); color: #1b1606; border-color: var(--moon); }

/* Log */
.log { font-size: 14px; }
.log div { padding: 6px 0; border-bottom: 1px solid var(--line); }
.log b { color: var(--muted); font-weight: 600; margin-right: 6px; font-size: 12px; }
.log .death { color: #ffb3b7; }
.log .vampire { color: #dcc6ff; }
.log .end { color: var(--moon); font-weight: 700; }

/* Toast */
#toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); z-index: 60; pointer-events: none; }
#toast div { background: #000c; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; margin-top: 6px; animation: up .2s; }

/* Winner */
.winner { text-align: center; padding: 26px 16px; }
.winner .big { font-family: Georgia, serif; font-size: 32px; color: var(--moon); margin: 8px 0; }
.winner .icon { font-size: 64px; }

/* Rules */
.rules h3 { margin-top: 22px; }
.rules ul { padding-left: 20px; }
.rules li { margin: 4px 0; }

.install .card { margin-top: 20px; }
@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
