:root {
  --bg: #0f1221;
  --panel: #191d33;
  --panel-soft: #222948;
  --text: #ecf0ff;
  --muted: #aeb7d6;
  --accent: #7c9dff;
  --danger: #ff6f7f;
  --success: #55d7a5;
  --warning: #ffcc66;
  --card-back: linear-gradient(145deg, #303a64, #1e2647);
  --shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  --radius: 14px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: radial-gradient(circle at top, #171d34 0%, var(--bg) 45%);
  color: var(--text);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0.5rem;
}

.skip-link:focus-visible {
  left: 0.5rem;
  background: #fff;
  color: #000;
  padding: 0.5rem;
  border-radius: 6px;
  z-index: 10;
}

.app {
  max-width: 980px;
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  gap: 1rem;
}

.top-bar h1 {
  margin: 0;
  font-size: clamp(1.6rem, 4vw, 2rem);
}

.subtitle {
  margin: 0.35rem 0 0;
  color: var(--muted);
}

.hud {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.hud-card {
  background: var(--panel);
  border: 1px solid #2e3865;
  border-radius: var(--radius);
  padding: 0.85rem;
  box-shadow: var(--shadow);
}

.hud-card:nth-child(1) {
  background: linear-gradient(145deg, #1f3b2f, #182a23);
  border-color: #3f8c6c;
}

.hud-card:nth-child(2) {
  background: linear-gradient(145deg, #2f284e, #221d39);
  border-color: #6f61b8;
}

.hud-card:nth-child(3) {
  background: linear-gradient(145deg, #3d2b24, #2a1f1a);
  border-color: #a06d54;
}

.hud-card:nth-child(4) {
  background: linear-gradient(145deg, #1f344c, #172638);
  border-color: #4c80b3;
}

.hud-card h2 {
  margin: 0 0 0.45rem;
  font-size: 0.95rem;
  color: var(--muted);
}

.hud-value {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.meter-wrap {
  display: grid;
  gap: 0.45rem;
}

progress {
  width: 100%;
  height: 0.65rem;
}

.muted {
  margin: 0.2rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid #41508d;
  border-radius: 11px;
  padding: 0.6rem 0.9rem;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition: transform 140ms ease, background-color 140ms ease, border-color 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

button:focus-visible,
input:focus-visible,
.game-card:focus-visible {
  outline: 3px solid var(--warning);
  outline-offset: 2px;
}

.debug-panel {
  background: var(--panel);
  border: 1px dashed #4a5ba0;
  border-radius: var(--radius);
  padding: 0.75rem;
  display: grid;
  gap: 0.55rem;
}

.debug-panel pre {
  max-height: 140px;
  overflow: auto;
  padding: 0.5rem;
  border-radius: 8px;
  background: #10162d;
}

.room-section h2 {
  margin: 0;
  text-align: center;
}

.room-section .muted {
  text-align: center;
  margin-top: 0.35rem;
}

.room-grid {
  margin-top: 0.7rem;
  display: grid;
  gap: 0.8rem;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  justify-items: stretch;
  overflow-x: auto;
  padding-bottom: 0.35rem;
}

.game-card {
  border: none;
  background: transparent;
  color: inherit;
  padding: 0;
  width: 100%;
  perspective: 900px;
}

.card-inner {
  border-radius: var(--radius);
  aspect-ratio: 5 / 7;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 420ms ease;
}

.game-card.revealed .card-inner {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  border: 1px solid #3c4a86;
  box-shadow: var(--shadow);
  padding: 0.8rem;
  backface-visibility: hidden;
}

.card-back {
  background: linear-gradient(to bottom, rgba(8, 11, 22, 0.25), rgba(8, 11, 22, 0.75)),
    url("./assets/deck.jpg");
  background-size: cover;
  background-position: center;
}

.card-front {
  transform: rotateY(180deg);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background-size: cover;
  background-position: center;
  color: #f4f7ff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.65);
}

.card-label {
  font-size: 0.93rem;
  color: var(--muted);
}

.card-rank {
  font-size: 2rem;
  font-weight: 800;
}

.card-meta {
  font-size: 0.9rem;
  color: #cbd5f4;
}

.game-card.resolved {
  opacity: 0.45;
  pointer-events: none;
}

.game-card.locked {
  opacity: 0.5;
}

.action-log {
  min-height: 160px;
  max-height: 220px;
  overflow: auto;
  border-radius: var(--radius);
  border: 1px solid #caa84d;
  background: linear-gradient(145deg, #111111, #000000);
  padding: 0.6rem;
  display: grid;
  gap: 0.45rem;
  color: #ffffff;
}

.log-entry {
  margin: 0;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid #8a6d1f;
  font-size: 0.95rem;
}

.result {
  border-radius: var(--radius);
  border: 1px solid #4a5ba0;
  background: var(--panel-soft);
  padding: 0.85rem;
  font-size: 1.05rem;
}

.result.win {
  border-color: var(--success);
}

.result.loss {
  border-color: var(--danger);
}

.hidden {
  display: none !important;
}

dialog {
  width: min(90vw, 680px);
  border: 1px solid #4a5ba0;
  border-radius: 16px;
  background: #131a35;
  color: var(--text);
  padding: 0;
}

dialog::backdrop {
  background: rgba(2, 6, 18, 0.68);
}

.modal-content {
  padding: 1rem 1.1rem 1.1rem;
}

.modal-content ul {
  padding-left: 1rem;
}

@media (max-width: 560px) {
  .room-grid {
    grid-template-columns: repeat(4, minmax(150px, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
