:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #eef4ff;
  --text: #172033;
  --muted: #66748a;
  --line: #dce5f2;
  --primary: #2563eb;
  --primary-2: #0f766e;
  --accent: #f59e0b;
  --danger: #dc2626;
  --ok: #16a34a;
  --shadow: 0 18px 45px rgba(25, 38, 68, .10);
  --radius: 8px;
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    linear-gradient(120deg, rgba(37, 99, 235, .08), transparent 38%),
    linear-gradient(240deg, rgba(15, 118, 110, .08), transparent 42%),
    var(--bg);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: inherit; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px clamp(16px, 4vw, 42px);
  background: rgba(255, 255, 255, .88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: white;
  display: grid;
  place-items: center;
  font-weight: 900;
  letter-spacing: 0;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.25rem, 2vw, 1.75rem);
  line-height: 1.05;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: .92rem;
}

.nav-links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.nav-links a,
.btn,
button.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 14px;
  text-decoration: none;
  font-weight: 750;
  font-size: .92rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease, background .15s ease;
}

.nav-links a:hover,
.btn:hover {
  transform: translateY(-1px);
  border-color: rgba(37, 99, 235, .45);
  box-shadow: 0 8px 22px rgba(37, 99, 235, .10);
}

.btn.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.btn.success {
  background: var(--ok);
  color: white;
  border-color: var(--ok);
}

.btn.warn {
  background: var(--accent);
  color: #271700;
  border-color: var(--accent);
}

.btn.danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

.btn.ghost {
  background: transparent;
}

.btn.small {
  min-height: 34px;
  padding: 7px 10px;
  font-size: .82rem;
}

.page {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: clamp(16px, 3vw, 34px);
}

.grid {
  display: grid;
  gap: 18px;
}

.grid.two { grid-template-columns: minmax(0, 1.3fr) minmax(340px, .7fr); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.card {
  background: rgba(255, 255, 255, .94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(16px, 2vw, 24px);
}

.card h2,
.card h3 {
  margin: 0 0 12px;
  line-height: 1.12;
}

.muted { color: var(--muted); }
.big { font-size: clamp(2rem, 5vw, 5.5rem); line-height: 1; letter-spacing: 0; }
.center { text-align: center; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; }

label {
  font-weight: 750;
  font-size: .9rem;
  color: #334155;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 12px;
  font: inherit;
  color: var(--text);
  background: white;
}

textarea {
  min-height: 130px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .88rem;
}

.notice {
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid #c7d7f8;
  color: #1e3a8a;
}

.error {
  color: #991b1b;
  background: #fee2e2;
  border-color: #fecaca;
}

.ok {
  color: #14532d;
  background: #dcfce7;
  border-color: #bbf7d0;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 5px 10px;
  font-weight: 800;
  font-size: .78rem;
  color: #334155;
  background: #f8fafc;
}

.screen-stage {
  min-height: 56vh;
  display: grid;
  align-content: center;
  gap: 24px;
}

.projector-question {
  font-size: clamp(2.2rem, 6vw, 6.6rem);
  line-height: 1.03;
  letter-spacing: 0;
  margin: 0;
}

.timer {
  font-size: clamp(2rem, 5vw, 5rem);
  font-weight: 950;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.qr-box {
  display: grid;
  place-items: center;
  gap: 12px;
  text-align: center;
}

.qr-box img,
.qr-box canvas {
  width: min(260px, 65vw);
  height: min(260px, 65vw);
  border: 12px solid white;
  border-radius: var(--radius);
  box-shadow: 0 12px 30px rgba(15, 23, 42, .16);
}

.code-party {
  font-size: clamp(2.5rem, 7vw, 6rem);
  font-weight: 950;
  letter-spacing: .12em;
  color: var(--primary);
}

.list {
  display: grid;
  gap: 10px;
}

.item {
  padding: 12px;
  border: 1px solid var(--line);
  background: white;
  border-radius: var(--radius);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.answer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.answer-card {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius);
  padding: 16px;
  min-height: 90px;
}

.phone-wrap {
  max-width: 560px;
  margin: 0 auto;
}

.mobile-action {
  width: 100%;
  min-height: 56px;
  font-size: 1.05rem;
}

.choice-btn {
  width: 100%;
  min-height: 58px;
  justify-content: flex-start;
  text-align: left;
  white-space: normal;
}

.ranking-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}

.ranking-list li {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(340px, .9fr) minmax(0, 1.1fr);
  gap: 18px;
}

.json-area {
  min-height: 420px;
}

.preview-frame {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0f172a;
  color: white;
  padding: 18px;
  min-height: 260px;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.game-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  padding: 16px;
  display: grid;
  gap: 10px;
}

.fullscreen-mode .topbar { display: none; }
.fullscreen-mode .page { width: 100%; padding: 18px; }
.fullscreen-mode .screen-stage { min-height: calc(100vh - 36px); }

@media (max-width: 920px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .nav-links { justify-content: flex-start; }
  .grid.two,
  .grid.three,
  .editor-layout { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .page { padding: 12px; }
  .card { padding: 14px; }
  .nav-links a { flex: 1 1 auto; }
  .projector-question { font-size: 2.2rem; }
  .row > .btn { flex: 1 1 auto; }
}
