/* Buttons */
button {
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.btn {
  transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.btn:active {
  transform: scale(0.96);
}

.primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 15px;
  font-size: 16px;
  font-weight: 800;
  width: 100%;
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.primary:hover {
  background: var(--primary-hover);
}

.primary.green {
  background: var(--green);
  box-shadow: 0 4px 16px rgba(22, 163, 74, 0.3);
}

.secondary {
  background: var(--card);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  font-size: 15px;
  font-weight: 800;
  width: 100%;
  box-shadow: var(--shadow-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.danger {
  background: var(--red);
  color: #fff;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 800;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 0 10px;
}

.iconbtn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-soft);
  font-size: 18px;
  color: var(--text);
  flex: none;
}

.title-lg {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: -1px;
  line-height: 1.05;
}

.title-sub {
  font-size: 13px;
  color: var(--subtle);
  font-weight: 600;
  margin-top: 2px;
}

/* Hero / Menu */
.hero {
  text-align: center;
  padding: 26px 0 18px;
}

.hero .logo {
  font-size: 42px;
  font-weight: 900;
  letter-spacing: -2px;
  line-height: 1;
  background: linear-gradient(90deg, var(--red), #f97316, var(--blue));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero .slogan {
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
  margin-top: 8px;
  letter-spacing: 0.2px;
}

.menu-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.menu-list-secondary {
  gap: 8px;
}

.menu-section-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.2px;
  margin: 6px 4px 0;
}

.menu-section-title-spaced {
  margin-top: 24px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 15px 16px;
  box-shadow: var(--shadow-card);
  text-align: left;
  width: 100%;
}

.menu-item .ic {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex: none;
}

.menu-item .t {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.2px;
}

.menu-item .d {
  font-size: 12px;
  color: var(--subtle);
  font-weight: 600;
  margin-top: 2px;
}

.menu-item .arr {
  margin-left: auto;
  color: var(--subtle);
  font-size: 18px;
  font-weight: 800;
}

.menu-item:focus-visible,
.tutorial-skip:focus-visible,
.iconbtn:focus-visible,
.primary:focus-visible,
.secondary:focus-visible,
.danger:focus-visible,
.wall-handle:focus-visible,
.hammer-handle:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.45);
  outline-offset: 3px;
}

.section-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--subtle);
  margin: 20px 4px 8px;
}

/* Cards / rows */
.card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow-card);
}

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

.seg {
  display: flex;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 3px;
  gap: 3px;
  flex-wrap: wrap;
}

.seg button {
  flex: 1;
  min-width: 50px;
  padding: 9px 8px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
  white-space: nowrap;
}

.seg button.on {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

.hint {
  font-size: 12px;
  color: var(--subtle);
  font-weight: 600;
  line-height: 1.45;
}

.toggle {
  width: 50px;
  height: 30px;
  border-radius: 15px;
  background: var(--border);
  position: relative;
  transition: background 0.2s;
  flex: none;
}

.toggle.on {
  background: #16a34a;
}

.toggle .knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  transition: left 0.2s;
}

.toggle.on .knob {
  left: 23px;
}

/* Game Topbar & Players Pills */
.game-top {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
  max-width: 560px;
}

.game-top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.players-pill-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}

.player-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px 8px 6px 6px;
  box-shadow: var(--shadow-soft);
  font-weight: 700;
  font-size: 12px;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.direction-badge {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  background: var(--player-color, var(--blue));
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.72);
  box-shadow: 0 2px 5px color-mix(in srgb, var(--player-color, var(--blue)) 42%, transparent);
  font-size: 14px;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.65);
}

.direction-badge.large {
  width: 34px;
  height: 34px;
  border-width: 3px;
  font-size: 21px;
}

.player-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-pill.active {
  border-color: var(--player-color, var(--blue));
  background: color-mix(in srgb, var(--player-color, var(--blue)) 10%, var(--card));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--player-color, var(--blue)) 35%, transparent), var(--shadow-soft);
  transform: translateY(-1px);
}

.player-pill.eliminated {
  opacity: 0.4;
  text-decoration: line-through;
}

.player-pill .walls-badge {
  font-size: 10px;
  background: var(--bg);
  border-radius: 6px;
  padding: 2px 5px;
  font-weight: 800;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.turn-banner {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px 9px 10px;
  border-left: 4px solid var(--player-color, var(--blue));
  border-radius: 12px;
  background: color-mix(in srgb, var(--player-color, var(--blue)) 8%, var(--card));
  box-shadow: var(--shadow-soft);
}

.turn-copy {
  min-width: 0;
  text-align: left;
}

.turn-title {
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.25;
}

.turn-goal {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  line-height: 1.35;
  margin-top: 2px;
}

.timer-badge {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  box-shadow: var(--shadow-soft);
}

.timer-badge.low {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.4);
}

.game-resign {
  max-width: 190px;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.15;
}

@media (max-width: 420px) {
  .players-pill-wrap {
    gap: 6px;
  }

  .player-pill {
    max-width: calc(50% - 3px);
    padding-right: 6px;
  }

  .game-resign {
    max-width: 136px;
    padding-inline: 9px;
  }
}

/* Online Lobby */
.lobby-code-box {
  background: var(--card);
  border: 2px dashed var(--blue);
  border-radius: 16px;
  padding: 16px;
  text-align: center;
  margin-bottom: 14px;
}

.room-code-display {
  font-size: 36px;
  font-weight: 900;
  letter-spacing: 6px;
  color: var(--blue);
  font-family: ui-monospace, Menlo, monospace;
  margin: 6px 0 10px;
}

.lobby-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.lobby-player-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.lobby-player-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow-soft);
}

.lobby-player-row.empty {
  opacity: 0.5;
  border-style: dashed;
}

.host-tag {
  font-size: 10px;
  font-weight: 800;
  background: #fef3c7;
  color: #92400e;
  padding: 2px 6px;
  border-radius: 6px;
}

body.dark .host-tag {
  background: #78350f;
  color: #fef3c7;
}

.ready-tag {
  font-size: 11px;
  font-weight: 800;
  color: #16a34a;
  margin-left: auto;
}

.input-text {
  width: 100%;
  padding: 13px 15px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  outline: none;
}

.input-text:focus {
  border-color: var(--blue);
}

.input-code {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 26px;
  letter-spacing: 4px;
  text-align: center;
  text-transform: uppercase;
}

.tutorial-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.3);
  text-align: center;
  animation: pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

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

.tutorial-kicker {
  color: var(--subtle);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.4px;
}

.tutorial-skip {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  padding: 4px;
}

.tutorial-board-wrap {
  display: flex;
  justify-content: center;
  margin: 4px 0 18px;
}

.tutorial-title {
  font-size: 20px;
  font-weight: 900;
  letter-spacing: -0.3px;
  margin-bottom: 8px;
}

.tutorial-description {
  color: var(--subtle);
  font-size: 13px;
  line-height: 1.55;
  margin: 0 auto 18px;
  max-width: 320px;
  min-height: 42px;
}

.tutorial-progress {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 18px;
}

.tutorial-progress-dot {
  width: 7px;
  height: 7px;
  border-radius: 4px;
  background: var(--border);
  transition: width 0.2s ease, background 0.2s ease;
}

.tutorial-progress-dot.active {
  width: 20px;
  background: var(--primary);
}

.tutorial-actions {
  display: flex;
  gap: 8px;
}

.tutorial-actions > button {
  flex: 1;
}

@keyframes pop {
  from {
    transform: scale(0.92);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.board-mini {
  margin: 0 auto 16px;
  position: relative;
  border: 1.5px solid var(--border);
  background: var(--grid-bg);
  box-shadow: var(--shadow-soft);
  border-radius: 10px;
  overflow: hidden;
}

.end-hero {
  text-align: center;
  padding: 30px 0 14px;
}

.end-hero .emoji {
  font-size: 60px;
  line-height: 1;
}

.end-hero .win-title {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: -1px;
  margin-top: 8px;
}

.end-hero .sub {
  font-size: 13px;
  color: var(--subtle);
  font-weight: 600;
  margin-top: 4px;
}

.confetti {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
  overflow: hidden;
}

.footer-btns {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.footer-btns button {
  flex: 1;
}

.footnote {
  font-size: 11px;
  color: var(--subtle);
  text-align: center;
  margin: 18px 0 24px;
  font-weight: 600;
  line-height: 1.5;
}
