:root {
  --bg0: #0d1418;
  --bg1: #132128;
  --bg2: #1c2f39;
  --fg: #e9f0ec;
  --fg-dim: #9fb1aa;
  --accent: #ffd54f;
  --accent-2: #79e1ff;
  --danger: #ff5e5e;
  --ok: #64d191;
  --card: #102027cc;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: Bahnschrift, "Segoe UI Variable", "Trebuchet MS", sans-serif;
  color: var(--fg);
  background: radial-gradient(1200px 700px at 20% -10%, #25414f, transparent 65%),
    radial-gradient(1400px 900px at 90% 120%, #402b20, transparent 65%),
    linear-gradient(150deg, var(--bg0), var(--bg1) 35%, var(--bg2));
}

body.mode-psy {
  animation: hueSpin 8s linear infinite;
}

@keyframes hueSpin {
  from { filter: hue-rotate(0deg) saturate(1.2); }
  to { filter: hue-rotate(360deg) saturate(1.45); }
}

body.mode-jobless .app-shell {
  filter: grayscale(0.82) contrast(1.05) brightness(0.9);
}

body.mode-jobless::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 180px #00000099;
}

.app-shell {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 14px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, #0f2027de, #203a43de);
  border: 1px solid #ffffff1f;
  box-shadow: var(--shadow);
}

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

.brand h1 {
  margin: 0;
  font-size: clamp(1.1rem, 3.2vw, 1.7rem);
  letter-spacing: 0.03em;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 15px #ffd54faa;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.author {
  border: 1px solid #ffffff2a;
  background: #ffffff0d;
  color: var(--accent-2);
  border-radius: 999px;
  padding: 7px 12px;
  font-weight: 700;
  cursor: pointer;
}

.layout {
  position: relative;
  min-height: 0;
}

.menu-panel {
  position: absolute;
  inset: 0;
  padding: clamp(14px, 2vw, 24px);
  border-radius: var(--radius);
  border: 1px solid #ffffff1f;
  background: linear-gradient(135deg, #11222bdd, #0b1519dd);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: 180ms ease;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 14px;
}

.menu-panel.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.eyebrow {
  margin: 0;
  color: var(--accent-2);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.75rem;
}

.menu-head h2 {
  margin: 2px 0 8px;
  font-size: clamp(1.4rem, 3.2vw, 2.1rem);
}

.sub {
  margin: 0;
  color: var(--fg-dim);
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.mode-card {
  border: 1px solid #ffffff1b;
  border-radius: 12px;
  padding: 13px;
  background: #0e1e24bd;
  cursor: pointer;
  min-height: 120px;
  transition: 140ms ease;
  outline: none;
}

.mode-card:hover,
.mode-card:focus-visible {
  border-color: #79e1ff8a;
  transform: translateY(-2px);
}

.mode-card.selected {
  border-color: #ffd54f9a;
  background: #182931f0;
}

.mode-card h3 {
  margin: 0 0 8px;
}

.mode-card p {
  margin: 0;
  color: var(--fg-dim);
  line-height: 1.32;
}

.menu-actions,
.actions-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.actions-col {
  display: grid;
  gap: 8px;
}

.btn {
  border: 1px solid #ffffff28;
  color: var(--fg);
  background: #17272fb8;
  border-radius: 10px;
  padding: 9px 13px;
  cursor: pointer;
  font-weight: 600;
}

.btn:hover {
  background: #1f333dfa;
}

.btn-primary {
  border-color: #e7bf4d6b;
  background: linear-gradient(180deg, #ffd54f, #e7ab2a);
  color: #1c1601;
}

.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-ghost {
  background: #ffffff0d;
}

.btn-danger {
  border-color: #ff5e5e7c;
  background: #4d1919;
}

.game-section {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  border: 1px solid #ffffff1f;
  background: #0b1419;
  overflow: hidden;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.hud {
  position: absolute;
  top: 10px;
  left: 10px;
  display: grid;
  gap: 6px;
  pointer-events: none;
}

.hud-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  border: 1px solid #ffffff2a;
  border-radius: 999px;
  padding: 6px 10px;
  background: #071015b7;
  font-size: 0.81rem;
}

.mobile-hint {
  position: absolute;
  right: 12px;
  bottom: 12px;
  background: #091014bb;
  border: 1px solid #ffffff1e;
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 0.75rem;
  color: var(--fg-dim);
}

.modal {
  position: fixed;
  inset: 0;
  background: #0306089e;
  display: none;
  place-items: center;
  z-index: 40;
}

.modal.open {
  display: grid;
}

.panel {
  width: min(480px, calc(100vw - 24px));
  background: linear-gradient(145deg, #0f1e25, #0b1318);
  border: 1px solid #ffffff2d;
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.panel-wide {
  width: min(900px, calc(100vw - 24px));
}

.panel h3,
.panel h4 {
  margin: 0 0 10px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.settings-grid label {
  display: grid;
  gap: 5px;
  font-size: 0.9rem;
}

.row-check {
  align-content: center;
}

.keymap {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.keymap-row {
  border: 1px solid #ffffff22;
  border-radius: 8px;
  padding: 7px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.keymap-row button {
  border: 1px solid #ffffff33;
  border-radius: 7px;
  background: #14222ab3;
  color: var(--accent-2);
  font-weight: 600;
  padding: 5px 8px;
  cursor: pointer;
}

.perk-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.perk-card {
  border: 1px solid #ffffff25;
  border-radius: 10px;
  padding: 10px;
  background: #0e1b22;
  cursor: pointer;
}

.perk-card:hover {
  border-color: #79e1ff96;
}

.stats {
  max-height: min(60vh, 560px);
  overflow: auto;
  border: 1px solid #ffffff1d;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 12px;
  background: #07101599;
}

.stats h4 {
  margin: 12px 0 8px;
}

.stats ul {
  margin: 0;
  padding-left: 18px;
  color: var(--fg-dim);
}

.toast-layer {
  position: fixed;
  right: 12px;
  top: 72px;
  z-index: 80;
  display: grid;
  gap: 6px;
}

.toast {
  background: #0d1e26f2;
  border: 1px solid #ffffff2d;
  border-left: 4px solid var(--accent);
  padding: 8px 10px;
  border-radius: 8px;
  min-width: 220px;
  box-shadow: var(--shadow);
}

body.mode-drunk .game-section {
  animation: drunkWobble 1.6s ease-in-out infinite;
}

@keyframes drunkWobble {
  0%, 100% { transform: translate(0px, 0px) rotate(0deg); }
  25% { transform: translate(1.8px, 0.8px) rotate(0.22deg); }
  50% { transform: translate(-1.6px, -1.2px) rotate(-0.28deg); }
  75% { transform: translate(1.4px, -0.6px) rotate(0.16deg); }
}

@media (max-width: 980px) {
  .mode-grid,
  .perk-grid,
  .settings-grid,
  .keymap {
    grid-template-columns: 1fr;
  }

  .top-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .mobile-hint {
    display: block;
  }
}
