:root {
  --bg: #101915;
  --panel: #1b2a20;
  --panel-light: #f5f3eb;
  --card: #263629;
  --accent: #f2c94c;
  --accent-2: #59c17f;
  --text: #f4f4ef;
  --muted: #a8b4a8;
  --shadow: rgba(0, 0, 0, 0.35);
  --font-title: "Rye", "Times New Roman", serif;
  --font-body: "IBM Plex Sans", "Noto Sans KR", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  background: radial-gradient(circle at top, #223425, #0d1411 60%);
  min-height: 100vh;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 50px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

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

.logo {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  font-size: 28px;
  background: var(--accent);
  color: #2c2100;
  border-radius: 16px;
  box-shadow: 0 12px 30px var(--shadow);
}

.title {
  font-family: var(--font-title);
  font-size: 28px;
  letter-spacing: 1px;
}

.subtitle {
  color: var(--muted);
  font-size: 14px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 14px;
}

.toggle input {
  accent-color: var(--accent);
}

body[data-screen="count"] .topbar,
body[data-screen="pick"] .topbar {
  display: none;
}

.screen {
  display: none;
  animation: fadeIn 0.35s ease;
}

.screen.active {
  display: block;
}

.panel {
  background: var(--panel);
  border-radius: 22px;
  padding: 22px;
  box-shadow: 0 22px 50px var(--shadow);
  margin-bottom: 20px;
}

.panel.light {
  background: var(--panel-light);
  color: #1d2a1f;
}

.panel.light .card {
  background: #ffffff;
}

.panel.centered {
  text-align: center;
  padding: 30px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-header h2 {
  margin: 0 0 6px 0;
  font-size: 22px;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  padding: 6px 12px;
  border-radius: 999px;
  margin: 18px auto;
}

.count {
  min-width: 34px;
  text-align: center;
  font-weight: 700;
  font-size: 18px;
}

.btn {
  border: none;
  cursor: pointer;
  background: var(--card);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 600;
  transition: transform 0.15s ease, background 0.15s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  background: #314434;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  color: #2c2100;
}

.btn.primary:hover:not(:disabled) {
  background: #f5d469;
}

.btn.ghost {
  background: transparent;
  border: 1px solid #3c5141;
}

.panel-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.actions-right {
  display: flex;
  gap: 10px;
}

.pick-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.pick-header h2 {
  margin: 0 0 6px 0;
  font-size: 22px;
}

.pick-status {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.pick-count {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}

.pick-count.shake {
  animation: shake 0.35s ease;
  color: #ffcf6e;
}

.slot-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(40px, 1fr));
  gap: 8px;
  min-width: 200px;
}

.slot-strip .slot {
  background: var(--card);
  border-radius: 12px;
  min-height: 46px;
  padding: 6px;
  border: 1px dashed #3b5243;
}

.pick-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
}

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

.slot {
  background: var(--card);
  border-radius: 16px;
  padding: 10px;
  min-height: 90px;
  display: grid;
  place-items: center;
  position: relative;
  border: 1px dashed transparent;
}

.slot.empty {
  border-color: #3b5243;
  color: var(--muted);
}

.slot .emoji,
.slot .avatar {
  font-size: 30px;
  width: 40px;
  height: 40px;
}

.slot .avatar {
  object-fit: cover;
  border-radius: 12px;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

.slot .name {
  font-size: 13px;
  margin-top: 4px;
}

.slot .remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: #ef6b6b;
  color: #fff;
  font-size: 12px;
  cursor: pointer;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}

.pick-cards {
  margin-top: 10px;
}

.card {
  background: #ffffff;
  padding: 16px;
  border-radius: 18px;
  text-align: center;
  border: 1px solid #e1e4d9;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  color: #283227;
  position: relative;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.12);
}

.card.selected {
  border-color: #2f8a56;
  box-shadow: 0 10px 24px rgba(47, 138, 86, 0.2);
}

.card.selected::after {
  content: "✓";
  position: absolute;
  top: 10px;
  right: 12px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #2f8a56;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 13px;
}

.card .emoji,
.card .avatar {
  font-size: 36px;
  width: 48px;
  height: 48px;
  margin: 0 auto 10px;
}

.card .avatar {
  object-fit: cover;
  border-radius: 16px;
}

.card .name {
  font-weight: 700;
  margin-bottom: 4px;
}

.card .trait {
  font-size: 13px;
  color: #657160;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 1fr);
  gap: 18px;
}

.canvas-wrap {
  position: relative;
}

#game-canvas {
  width: 100%;
  height: auto;
  border-radius: 22px;
  background: #0d1411;
  box-shadow: inset 0 0 0 2px #1f2b1f, 0 20px 50px var(--shadow);
}

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 16, 12, 0.6);
  border-radius: 22px;
  font-family: var(--font-title);
  font-size: 64px;
  letter-spacing: 2px;
  color: #f4e4b1;
  text-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.countdown.hidden {
  display: none;
}

.game-left {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.game-actions {
  display: flex;
  gap: 12px;
}

.game-right {
  background: var(--panel);
  border-radius: 22px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 50px var(--shadow);
}

.stat {
  background: var(--card);
  border-radius: 12px;
  padding: 10px 12px;
}

.stat .label {
  color: var(--muted);
  font-size: 12px;
}

.stat .value {
  font-size: 18px;
  font-weight: 600;
}

.log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.log-title {
  font-size: 13px;
  color: var(--muted);
}

.log-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow: auto;
  font-size: 13px;
}

.log-list li {
  background: #1e2b22;
  border-radius: 8px;
  padding: 6px 8px;
}

.results {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.results li {
  background: var(--card);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}

.results li.first {
  background: linear-gradient(120deg, #f2c94c, #f7e4a1);
  color: #2c2100;
}

@media (max-width: 900px) {
  .game-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
  .panel-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .actions-right {
    flex-direction: column;
  }
  .game-actions {
    flex-direction: column;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  body[data-screen="game"] .topbar {
    display: none;
  }
  body[data-screen="game"] .app {
    padding: 8px;
  }
  body[data-screen="game"] .game-layout {
    grid-template-columns: 1fr;
  }
  body[data-screen="game"] .game-right {
    display: none;
  }
  body[data-screen="game"] #game-canvas {
    border-radius: 12px;
  }

  body[data-screen="pick"] .pick-header {
    margin-bottom: 8px;
  }
  body[data-screen="pick"] .pick-cards {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }
  body[data-screen="pick"] .pick-actions {
    margin-top: 10px;
  }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes shake {
  0% { transform: translateX(0); }
  30% { transform: translateX(-4px); }
  60% { transform: translateX(4px); }
  100% { transform: translateX(0); }
}
