/* Wurst Game — Responsive styles & 3 themes (cove, biergarten, frost) */

:root {
  --bg-glass: rgba(255, 250, 240, 0.86);
  --bg-glass-strong: rgba(255, 250, 240, 0.96);
  --border-glass: rgba(120, 74, 38, 0.18);
  --text-main: #2a1c14;
  --text-muted: #6c5241;
  --accent: #d9532f;
  --accent-hover: #be401e;
  --accent-soft: rgba(217, 83, 47, 0.14);
  --gold: #d99b1e;
  --danger: #c62828;
  --shadow: 0 10px 30px rgba(22, 38, 56, 0.18);
  --radius: 14px;
  --font-sans: ui-rounded, 'SF Pro Rounded', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html[data-theme="biergarten"] {
  --bg-glass: rgba(26, 34, 56, 0.86);
  --bg-glass-strong: rgba(24, 31, 52, 0.96);
  --border-glass: rgba(255, 198, 128, 0.2);
  --text-main: #f8efe4;
  --text-muted: #c2b29e;
  --accent: #e87a35;
  --accent-hover: #ff8e47;
  --accent-soft: rgba(232, 122, 53, 0.22);
  --gold: #f5b942;
  --shadow: 0 12px 32px rgba(6, 10, 22, 0.45);
}

html[data-theme="frost"] {
  --bg-glass: rgba(246, 250, 255, 0.86);
  --bg-glass-strong: rgba(248, 251, 255, 0.96);
  --border-glass: rgba(65, 95, 125, 0.18);
  --text-main: #1d2c3b;
  --text-muted: #566b80;
  --accent: #c94c5b;
  --accent-hover: #ae3746;
  --accent-soft: rgba(201, 76, 91, 0.14);
  --gold: #c98a18;
  --shadow: 0 10px 28px rgba(32, 52, 78, 0.16);
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  color: var(--text-main);
  background: #1b9ce0;
  user-select: none;
  overscroll-behavior: none;
}

.app-shell {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
}

#game-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: auto;
  touch-action: none;
}

/* --- Top HUD --- */
.top-bar {
  position: relative;
  z-index: 10;
  padding: max(10px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.top-row {
  width: 100%;
  max-width: 820px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  white-space: nowrap;
  border-radius: 999px;
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.brand-mark {
  width: 22px;
  height: 22px;
  color: var(--accent);
  display: inline-flex;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-title b {
  color: var(--accent);
  font-weight: 900;
}

.action-cluster {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 38px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid var(--border-glass);
  background: var(--bg-glass);
  color: var(--text-main);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, background 0.15s ease;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.icon-btn:hover {
  transform: translateY(-1px);
  background: var(--bg-glass-strong);
}

button, summary {
  touch-action: manipulation;
}

:is(button, input, summary):focus-visible,
.gamepad-navigation :is(button, input, summary):focus {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

input.gamepad-editing {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
  background: var(--accent-soft);
}

.icon-btn:active {
  transform: scale(0.95);
}

.icon-btn-accent {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.icon-btn-accent:hover {
  background: var(--accent-hover);
}

.scoreboard {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 14px;
  padding: 6px 18px;
  border-radius: 999px;
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}

.stat-k {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 700;
}

.stat-v {
  font-size: 0.96rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* --- Stage & Floating Controls --- */
.stage-wrap {
  position: relative;
  flex: 1;
  z-index: 8;
  pointer-events: none;
}

.stage-toast {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%) translateY(-12px);
  padding: 9px 18px;
  border-radius: 999px;
  background: var(--bg-glass-strong);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  font-size: 0.92rem;
  font-weight: 700;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
  max-width: calc(100vw - 28px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.stage-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.stage-toast.toast-danger {
  background: #b71c1c;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.25);
}

.stage-toast.toast-hint {
  background: var(--accent);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.25);
}

.fab {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: 16px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--border-glass);
  background: var(--bg-glass);
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  transition: transform 0.14s ease;
}

.fab svg {
  width: 22px;
  height: 22px;
}

.fab:hover {
  transform: scale(1.06);
}

.fab:active {
  transform: scale(0.94);
}

/* Mobile D-Pad */
.mobile-dpad {
  position: absolute;
  left: max(16px, env(safe-area-inset-left));
  bottom: 12px;
  width: 138px;
  height: 138px;
  display: none;
  pointer-events: auto;
}

.dpad-btn {
  touch-action: none;
  position: absolute;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border-glass);
  background: var(--bg-glass);
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

.dpad-btn svg {
  width: 22px;
  height: 22px;
}

.dpad-btn:is(:active, .is-pressed) {
  background: var(--accent);
  color: #fff;
  transform: scale(0.92);
}

.dpad-up { top: 0; left: 47px; }
.dpad-down { bottom: 0; left: 47px; }
.dpad-left { top: 47px; left: 0; }
.dpad-right { top: 47px; right: 0; }

/* --- Bottom Dock --- */
.bottom-dock {
  position: relative;
  z-index: 10;
  padding: 0 max(14px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.dock-controls {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 999px;
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.dock-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--text-main);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.14s ease, transform 0.12s ease;
}

.dock-btn svg {
  width: 18px;
  height: 18px;
}

.dock-btn:hover {
  background: var(--accent-soft);
}

.dock-btn:active {
  transform: scale(0.95);
}

.dock-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.dock-hint {
  font-size: 0.76rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

/* --- Modals --- */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(12, 18, 28, 0.5);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.scrim.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 50;
  width: min(440px, calc(100vw - 28px));
  max-height: calc(100dvh - max(20px, env(safe-area-inset-top)) - max(20px, env(safe-area-inset-bottom)));
  overscroll-behavior: contain;
  touch-action: pan-y;
  overflow-y: auto;
  border-radius: 20px;
  background: var(--bg-glass-strong);
  border: 1px solid var(--border-glass);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
}

.hidden {
  display: none !important;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 10px;
  border-bottom: 1px solid var(--border-glass);
}

.modal-head h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
}

.modal-close {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.modal-close svg {
  width: 20px;
  height: 20px;
}

.modal-close:hover {
  background: var(--accent-soft);
  color: var(--text-main);
}

.modal-body {
  padding: 16px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.diff-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.diff-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 2px solid var(--border-glass);
  background: transparent;
  color: var(--text-main);
  font: inherit;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.14s ease, background 0.14s ease;
}

.diff-card strong {
  font-size: 0.98rem;
}

.diff-card span {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.diff-card:hover, .diff-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.custom-section {
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  padding: 10px 12px;
}

.custom-section summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 0.9rem;
}

.custom-grid {
  margin: 10px 0 12px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.custom-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
}

.custom-grid input {
  width: 100%;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border-glass);
  background: var(--bg-glass);
  color: var(--text-main);
  font: inherit;
  font-weight: 700;
}

.seed-row {
  display: flex;
  gap: 8px;
}

.seed-row input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-glass);
  background: var(--bg-glass);
  color: var(--text-main);
  font: inherit;
  font-size: 0.88rem;
}

.primary-btn, .secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 16px;
  border-radius: 12px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
  border: none;
  transition: transform 0.1s ease, background 0.14s ease;
}

.primary-btn svg, .secondary-btn svg {
  width: 17px;
  height: 17px;
}

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

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

.secondary-btn {
  background: var(--accent-soft);
  color: var(--text-main);
}

.secondary-btn:hover {
  filter: brightness(0.95);
}

.full-width {
  width: 100%;
}

.mini-stats {
  display: flex;
  justify-content: space-around;
  padding: 12px;
  border-radius: 14px;
  background: var(--accent-soft);
}

.mini-stats > div {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.mini-k {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 700;
}

.mini-stats strong {
  font-size: 1.35rem;
  font-weight: 900;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.daily-date-line {
  margin: 0;
  font-size: 0.95rem;
}

.daily-status {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.help-body p, .help-body li {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.48;
}

.help-body ul {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.help-keys code {
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--accent-soft);
  font-weight: 700;
}

.vic-body {
  text-align: center;
}

.vic-badge {
  display: inline-block;
  align-self: center;
  padding: 6px 16px;
  border-radius: 999px;
  background: var(--gold);
  color: #fff;
  font-weight: 900;
  font-size: 0.92rem;
  letter-spacing: 0.02em;
}

/* --- Responsive Mobile / Touch --- */
@media (max-width: 680px) {
  .btn-lbl {
    display: none;
  }
  .action-cluster {
    gap: 4px;
  }
  .icon-btn {
    width: 42px;
    height: 44px;
    padding: 0;
  }
  .scoreboard {
    gap: 10px;
    padding: 5px 12px;
  }
  .stat-diff {
    display: none;
  }
  .mobile-dpad {
    display: block;
  }
  .dock-hint {
    display: none;
  }
}

@media (max-width: 430px) {
  .top-bar {
    padding-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right));
  }
  .top-row {
    gap: 5px;
  }
  .brand {
    gap: 4px;
    padding: 8px;
  }
  .brand-mark {
    width: 16px;
    height: 16px;
  }
  .brand-title {
    font-size: 0.82rem;
  }
  .action-cluster {
    flex: 0 1 284px;
    min-width: 0;
  }
  .icon-btn {
    flex: 1 1 0;
    min-width: 0;
  }
}

@media (hover: none) and (pointer: coarse) {
  .modal input {
    font-size: 16px;
  }
  .mobile-dpad {
    display: block;
  }
  .dock-hint {
    display: none;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .top-bar {
    flex-direction: row;
    justify-content: space-between;
    padding: max(6px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  }
  .top-row {
    width: auto;
    flex: 1;
    min-width: 0;
  }
  .action-cluster {
    min-width: 0;
  }
  .btn-lbl, .stat-diff {
    display: none;
  }
  .icon-btn {
    width: clamp(32px, 5.5vw, 44px);
    min-width: 0;
    height: 40px;
    padding: 0;
  }
  .scoreboard {
    gap: 8px;
    padding: 4px 10px;
  }
  .mobile-dpad {
    width: 132px;
    height: 132px;
  }
  .dpad-up, .dpad-down { left: 44px; }
  .dpad-left, .dpad-right { top: 44px; }
}

@media (max-height: 520px) and (max-width: 650px) and (orientation: landscape) {
  .stat-streak {
    display: none;
  }
}

@media (max-height: 520px) and (max-width: 520px) and (orientation: landscape) {
  .top-bar {
    flex-direction: column;
  }
  .top-row {
    width: 100%;
    flex: auto;
  }
}
