:root {
  --bg: #05060f;
  --bg2: #0b0e24;
  --panel: #12152f;
  --panel-border: #2a2f5c;
  --cyan: #4bf2e8;
  --purple: #a06bff;
  --pink: #ff5cb8;
  --orange: #ffb347;
  --green: #4ade80;
  --red: #ff5c5c;
  --text: #e8e9f5;
  --text-dim: #9699c0;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(ellipse at top, var(--bg2) 0%, var(--bg) 70%);
  color: var(--text);
  font-family: 'Rubik', sans-serif;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

h1, h2, h3 {
  font-family: 'Orbitron', sans-serif;
}

.stars {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-image:
    radial-gradient(1px 1px at 20px 30px, white, transparent),
    radial-gradient(1px 1px at 120px 80px, white, transparent),
    radial-gradient(1.5px 1.5px at 60px 140px, white, transparent),
    radial-gradient(1px 1px at 220px 60px, white, transparent),
    radial-gradient(1.5px 1.5px at 300px 200px, white, transparent),
    radial-gradient(1px 1px at 400px 40px, white, transparent),
    radial-gradient(1px 1px at 500px 160px, white, transparent),
    radial-gradient(1.5px 1.5px at 600px 100px, white, transparent);
  background-repeat: repeat;
  background-size: 650px 650px;
  opacity: 0.6;
  pointer-events: none;
}

.landing {
  position: relative;
  z-index: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: 48px 20px 80px;
}

.brand {
  text-align: center;
  margin-bottom: 40px;
}

.brand h1 {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: 2px;
  margin: 0;
  color: var(--text);
  text-shadow: 0 0 20px rgba(160, 107, 255, 0.6);
}

.brand h1 span {
  color: var(--cyan);
  text-shadow: 0 0 20px rgba(75, 242, 232, 0.8);
}

.tagline {
  color: var(--text-dim);
  margin-top: 12px;
  font-size: 1.05rem;
}

.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 40px;
}

@media (max-width: 720px) {
  .panel-grid { grid-template-columns: 1fr; }
}

.panel {
  background: linear-gradient(160deg, var(--panel), #0d1026);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 0 30px rgba(75, 242, 232, 0.05);
}

.panel h2 {
  margin-top: 0;
  font-size: 1.3rem;
  color: var(--cyan);
}

.hint {
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.4;
}

.hint.small { font-size: 0.8rem; }

label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin: 14px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: #090b1c;
  color: var(--text);
  font-size: 1rem;
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(75, 242, 232, 0.15);
}

.btn {
  display: inline-block;
  margin-top: 18px;
  padding: 12px 20px;
  border-radius: 10px;
  border: none;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  color: #050614;
  box-shadow: 0 0 20px rgba(75, 242, 232, 0.35);
  width: 100%;
}

.btn-secondary {
  background: linear-gradient(135deg, var(--pink), var(--purple));
  color: #050614;
  width: 100%;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--text);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.error {
  color: var(--red);
  font-size: 0.85rem;
  min-height: 18px;
  margin-top: 8px;
}

.rules {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 20px 24px;
}

.rules h3 { margin-top: 0; color: var(--orange); }
.rules ul { margin: 0; padding-left: 20px; color: var(--text-dim); line-height: 1.6; }
.rules li { margin-bottom: 6px; }

/* ---- App / game shell ---- */

.app {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

.hidden { display: none !important; }

.view { animation: fadein 0.3s ease; }

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

/* Waiting room */

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

.room-header h1 { font-size: 1.6rem; margin: 0; }
.room-header span { color: var(--cyan); letter-spacing: 4px; }

.player-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
  margin: 24px 0;
}

.player-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
  position: relative;
}

.player-card .avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  background: linear-gradient(135deg, var(--purple), var(--cyan));
  color: #050614;
}

.player-card .name { font-weight: 600; }
.player-card .badge {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(255, 179, 71, 0.15);
  color: var(--orange);
}

.player-card.offline { opacity: 0.4; }

#start-btn { max-width: 320px; }

/* Game header */

.game-header {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 14px 20px;
}

.room-pill, .deck-pill {
  font-size: 0.85rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.room-pill strong, .deck-pill strong { color: var(--text); }

.engine-meter { flex: 1; min-width: 200px; }

.meter-label {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.meter-bar {
  height: 14px;
  border-radius: 10px;
  background: #090b1c;
  border: 1px solid var(--panel-border);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--orange), var(--pink), var(--cyan));
  transition: width 0.5s ease;
  box-shadow: 0 0 12px rgba(255, 179, 71, 0.6);
}

.turn-banner {
  margin: 18px 0;
  padding: 10px 18px;
  border-radius: 10px;
  background: rgba(160, 107, 255, 0.12);
  border: 1px solid var(--purple);
  color: var(--text);
  font-weight: 600;
  text-align: center;
}

.turn-banner.my-turn {
  background: rgba(75, 242, 232, 0.15);
  border-color: var(--cyan);
  box-shadow: 0 0 20px rgba(75, 242, 232, 0.25);
}

.board {
  display: grid;
  grid-template-columns: 1fr 280px;
  grid-template-areas:
    "players players"
    "main    log";
  gap: 16px;
  margin-top: 10px;
  align-items: start;
}

@media (max-width: 860px) {
  .board {
    grid-template-columns: 1fr;
    grid-template-areas:
      "players"
      "main"
      "log";
  }
}

.players-strip {
  grid-area: players;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.player-chip {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.85rem;
  position: relative;
}

.player-chip.active-turn {
  border-color: var(--cyan);
  box-shadow: 0 0 16px rgba(75, 242, 232, 0.3);
}

.player-chip.offline { opacity: 0.4; }

.player-chip .chip-name { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.player-chip .chip-stats { color: var(--text-dim); margin-top: 4px; display: flex; gap: 10px; }

.player-chip .chip-stats .keys-badge {
  display: inline-block;
  border-radius: 8px;
  padding: 0 4px;
}

.player-chip .chip-stats .keys-badge.key-flash {
  animation: keyFlash 0.9s ease;
}

@keyframes keyFlash {
  0% { transform: scale(1); }
  25% { transform: scale(1.5); color: var(--orange); text-shadow: 0 0 10px var(--orange); }
  100% { transform: scale(1); }
}

.main-stage {
  grid-area: main;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.log-sidebar {
  grid-area: log;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 14px 16px;
  max-height: 520px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.log-sidebar h3 { margin: 0 0 8px; font-size: 0.95rem; color: var(--text-dim); }

.log-sidebar ul {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.log-sidebar li {
  font-size: 0.8rem;
  color: var(--text-dim);
  border-left: 2px solid var(--panel-border);
  padding-left: 10px;
  line-height: 1.35;
}

.last-action-panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 90px;
}

.last-action-panel .la-card {
  width: 70px;
  height: 98px;
  border-radius: 10px;
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}

.last-action-panel .la-text {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.3;
}

.last-action-panel .la-text .la-player { color: var(--cyan); }
.last-action-panel .la-text .la-sub { display: block; font-size: 0.85rem; font-weight: 500; color: var(--text-dim); margin-top: 4px; }

.last-action-panel.pop {
  animation: lastActionPop 0.5s ease;
}

.last-action-panel.key-event {
  border-color: var(--orange);
  box-shadow: 0 0 24px rgba(255, 179, 71, 0.35);
}

@keyframes lastActionPop {
  0% { transform: scale(0.96); box-shadow: 0 0 0 rgba(75, 242, 232, 0); }
  40% { transform: scale(1.015); box-shadow: 0 0 24px rgba(75, 242, 232, 0.4); }
  100% { transform: scale(1); }
}

.hand-area {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 16px 20px;
}

.hand-area h3 { margin-top: 0; font-size: 1rem; color: var(--text-dim); }

.hand {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 110px;
}

.card {
  width: 92px;
  height: 129px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #050614;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  text-align: center;
  padding: 6px;
  gap: 6px;
  flex-shrink: 0;
}

.card:hover { transform: translateY(-6px); }

.card.selected {
  border-color: white;
  box-shadow: 0 0 16px rgba(255,255,255,0.6);
  transform: translateY(-8px);
}

.card .icon { font-size: 1.8rem; }

.card.energy { background: linear-gradient(160deg, #ffd27a, var(--orange)); }
.card.key { background: linear-gradient(160deg, #9effd0, var(--green)); }
.card.sabotage { background: linear-gradient(160deg, #ff9ad6, var(--pink)); }

.card.card-img {
  background-size: cover;
  background-position: center;
  padding: 0;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}

.card.card-img.back-face {
  cursor: default;
}

.card-back-row {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.card-back-mini {
  width: 20px;
  height: 28px;
  border-radius: 4px;
  background-image: url('../images/cards/back.png');
  background-size: cover;
  background-position: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
  flex-shrink: 0;
}

.deck-pill {
  display: flex;
  align-items: center;
  gap: 6px;
}

.deck-pill .card-back-mini {
  width: 18px;
  height: 25px;
}

.action-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.action-bar .btn { margin-top: 0; width: auto; }

/* Target modal */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(2,3,10,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-box {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 24px;
  width: 90%;
  max-width: 380px;
  text-align: center;
}

.target-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0;
}

.target-list button {
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: #090b1c;
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
}

.target-list button:hover { border-color: var(--cyan); }

/* End screen */

.end-card {
  max-width: 560px;
  margin: 80px auto;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 40px;
  text-align: center;
}

.end-card h1 {
  font-size: 2rem;
  color: var(--cyan);
  text-shadow: 0 0 20px rgba(75,242,232,0.5);
}

.winners-list {
  margin: 20px 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.winner-pill {
  background: rgba(74, 222, 128, 0.15);
  border: 1px solid var(--green);
  color: var(--green);
  padding: 6px 14px;
  border-radius: 20px;
  font-weight: 700;
}
