html,
body {
  height: 100%;
  overflow: hidden;
}

:root {
  --bg: #10263e;
  --panel: #1f3550;
  --panel-2: #173049;
  --line: #0b1520;
  --text: #f7f2cf;
  --muted: #c6d0bf;
  --accent: #e2bb4f;
  --team-primary: #2f7cc6;
  --team-secondary: #153458;
  --team-accent: #eebc4b;
  --team-text: #f6f3de;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Arial Black", Impact, "Trebuchet MS", sans-serif;
  background:
    radial-gradient(circle at 20% 12%, rgba(255, 255, 255, 0.18), transparent 12%),
    radial-gradient(circle at 82% 9%, rgba(255, 255, 255, 0.12), transparent 10%),
    linear-gradient(180deg, #5b86b2 0 12%, #2b4e73 12% 22%, #10263e 22% 100%);
  color: var(--text);
  overscroll-behavior: none;
  touch-action: manipulation;
}

body[data-device="tablet"],
body[data-device="mobile"] {
  touch-action: none;
}

.game-shell {
  width: min(1320px, calc(100vw - 32px));
  margin: 0 auto;
  height: 100dvh;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  grid-template-areas:
    "title title"
    "info play";
  gap: 18px;
  align-items: stretch;
  padding: 18px 0 24px;
  position: relative;
  overflow: hidden;
}

.game-shell::before {
  content: "";
  position: absolute;
  inset: 24px 0 12px;
  background:
    radial-gradient(circle at center, rgba(13, 26, 39, 0.18), transparent 55%),
    linear-gradient(90deg, rgba(9, 18, 27, 0.45), transparent 16%, transparent 84%, rgba(9, 18, 27, 0.45));
  pointer-events: none;
}

.play-panel {
  background: var(--panel);
  border: 4px solid var(--line);
  box-shadow:
    inset 0 0 0 4px rgba(255, 255, 255, 0.05),
    0 10px 0 rgba(8, 15, 22, 0.35);
}

.top-title {
  grid-area: title;
  display: flex;
  justify-content: center;
  align-items: center;
}

.info-panel {
  grid-area: info;
  position: relative;
  z-index: 1;
  min-height: 0;
  overflow: hidden;
}

body.franchise-setup-pending #homepageHero,
body.franchise-setup-pending #franchiseMainContent,
body.franchise-setup-pending #startButton {
  display: none !important;
}

body.franchise-slot-selecting #homepageHero,
body.franchise-slot-selecting #onboardingPanel,
body.franchise-slot-selecting #franchiseMainContent,
body.franchise-slot-selecting #startButton {
  display: none !important;
}

body.franchise-setup-pending #onboardingPanel {
  display: block !important;
}

body.franchise-slot-selecting #loadSavePanel {
  display: block !important;
}

.top-title h1 {
  margin: 0;
  padding: 6px 18px 2px;
  font-size: clamp(2.4rem, 5vw, 4.2rem);
  line-height: 1;
  text-transform: uppercase;
  color: var(--text);
  text-shadow: 0 3px 0 rgba(8, 15, 22, 0.45);
}

.play-panel::before {
  content: "";
  display: block;
  height: 10px;
  margin: -14px -14px 12px;
  background: var(--accent);
  border-bottom: 4px solid var(--line);
}

.eyebrow,
.label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  color: #d7e0cb;
}

h2,
p {
  margin: 0;
}

.subtitle {
  margin-top: 12px;
  color: #d5dfcd;
  line-height: 1.45;
  font-family: "Trebuchet MS", sans-serif;
  font-weight: 700;
}

.scoreboard,
.status-row {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.scoreboard {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.score-card,
.status-pill,
.instructions {
  background: var(--panel-2);
  border: 3px solid var(--line);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.04);
}

.score-card,
.status-pill {
  padding: 12px 14px;
}

.score-card strong,
.status-pill strong {
  display: block;
  margin-top: 8px;
  font-size: 1.12rem;
  color: var(--team-accent);
  text-transform: uppercase;
}

.instructions {
  margin-top: 18px;
  padding: 16px;
}

.instructions h2 {
  font-size: 1rem;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.instructions p {
  font-family: "Trebuchet MS", sans-serif;
  font-weight: 700;
  line-height: 1.45;
  color: #e8e1be;
}

.instructions p + p {
  margin-top: 8px;
}

.touch-instructions {
  display: none;
}

.play-panel {
  grid-area: play;
  padding: 14px;
  background:
    linear-gradient(180deg, #203a57 0, #162c41 100%);
  min-height: 0;
  display: flex;
  overflow: hidden;
}

.canvas-frame {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 12px;
  background:
    linear-gradient(180deg, #1d3a56 0 18%, #0f2335 18% 100%);
  border: 4px solid var(--line);
  overflow: hidden;
}

.canvas-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.06) 0 2%, transparent 2% 98%, rgba(255, 255, 255, 0.06) 98% 100%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.08) 0 4%, transparent 4% 100%);
  pointer-events: none;
}

canvas {
  display: block;
  width: min(100%, 760px);
  height: auto;
  max-height: 100%;
  aspect-ratio: 3 / 4;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 6px solid #09080d;
  background: #254529;
}

.overlay {
  position: absolute;
  inset: 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 12px;
  padding: 24px;
  background: rgba(15, 28, 42, 0.94);
  border: 4px solid var(--line);
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.04);
  overflow: auto;
}

.overlay.hidden {
  display: none;
}

.overlay h2 {
  font-size: 2rem;
  text-transform: uppercase;
  color: var(--team-accent);
  background: #14283f;
  border: 3px solid var(--line);
  padding: 8px 16px;
}

.overlay p {
  max-width: 28ch;
  color: var(--text);
  font-family: "Trebuchet MS", sans-serif;
  font-weight: 700;
  line-height: 1.45;
}

.homepage {
  width: min(100%, 560px);
  display: grid;
  gap: 14px;
}

#franchiseMainContent {
  display: grid;
  gap: 14px;
}

.homepage-kicker {
  color: #d3dec8;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
}

.homepage-hero {
  display: grid;
  gap: 10px;
}

.homepage-hero p {
  max-width: none;
}

.franchise-card,
.runner-select,
.franchise-module,
.runner-feature,
.season-chip {
  background: rgba(20, 40, 63, 0.94);
  border: 3px solid var(--line);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.04);
}

.franchise-card {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  text-align: left;
  padding: 14px;
}

.load-save-panel {
  display: grid;
  gap: 12px;
}

.franchise-slot-grid {
  display: grid;
  gap: 10px;
}

.franchise-slot {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: rgba(12, 25, 38, 0.72);
  border: 3px solid var(--line);
  text-align: left;
}

.franchise-slot.active {
  border-color: var(--team-accent);
  background: rgba(226, 187, 79, 0.16);
}

.franchise-slot.empty {
  background: rgba(12, 25, 38, 0.48);
}

.franchise-slot strong {
  display: block;
  color: var(--team-accent);
  text-transform: uppercase;
}

.franchise-slot span {
  display: block;
  margin-top: 4px;
  color: #dce4d2;
  font-family: "Trebuchet MS", sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

.slot-button {
  min-width: 96px;
  padding-inline: 12px;
}

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

.season-chip {
  padding: 12px;
  text-align: left;
}

.season-chip strong {
  display: block;
  margin-top: 6px;
  color: var(--team-accent);
  text-transform: uppercase;
}

.franchise-card strong {
  display: block;
  margin-top: 6px;
  color: var(--team-accent);
  text-transform: uppercase;
}

.franchise-dashboard {
  display: grid;
  gap: 12px;
  grid-template-columns: 1.05fr 1.15fr;
}

.franchise-module,
.runner-feature {
  padding: 14px;
  text-align: left;
}

.module-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
}

.module-head h3 {
  margin: 0;
  font-size: 0.98rem;
  text-transform: uppercase;
}

.module-head span {
  color: #dce7d2;
  font-size: 0.76rem;
  text-transform: uppercase;
}

.fan-meter {
  height: 16px;
  background: #0f2133;
  border: 2px solid var(--line);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.04);
  overflow: hidden;
}

.fan-meter-fill {
  height: 100%;
  width: 50%;
  background: linear-gradient(90deg, #c84d33, #e2bb4f 55%, #69b76c);
}

.franchise-module p,
.runner-feature p {
  max-width: none;
  margin-top: 10px;
  color: #dce4d2;
  font-size: 0.9rem;
  line-height: 1.42;
}

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

.setup-field {
  display: grid;
  gap: 6px;
}

.setup-field input {
  width: 100%;
  border: 3px solid var(--line);
  background: #12273c;
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  font-size: 0.92rem;
}

.setup-field input[type="color"] {
  min-height: 48px;
  padding: 4px;
}

.schedule-list {
  display: grid;
  gap: 8px;
}

.schedule-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  background: rgba(12, 25, 38, 0.72);
  border: 2px solid rgba(11, 21, 32, 0.9);
}

.schedule-item.active {
  border-color: var(--team-accent);
  background: rgba(226, 187, 79, 0.16);
}

.schedule-item.complete {
  background: rgba(77, 133, 84, 0.18);
}

.schedule-item.win {
  border-color: rgba(88, 176, 98, 0.95);
  background: rgba(64, 143, 73, 0.28);
}

.schedule-item.loss {
  border-color: rgba(188, 67, 67, 0.95);
  background: rgba(132, 41, 41, 0.28);
}

.schedule-week,
.schedule-result {
  font-size: 0.72rem;
  text-transform: uppercase;
  color: #d5dfcd;
}

.schedule-item.win .schedule-result {
  color: #92e08d;
}

.schedule-item.loss .schedule-result {
  color: #ff9f9f;
}

.schedule-opponent {
  font-size: 0.92rem;
  color: var(--text);
  text-transform: uppercase;
}

.runner-feature strong {
  display: block;
  font-size: 1.02rem;
  color: var(--team-accent);
  text-transform: uppercase;
}

.runner-select {
  padding: 14px;
  text-align: left;
}

.runner-select-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 12px;
}

.runner-select-head h3 {
  margin: 0;
  font-size: 1rem;
  text-transform: uppercase;
}

.runner-select-head p {
  max-width: none;
  color: #d9e4cf;
  font-size: 0.85rem;
}

.runner-grid {
  display: grid;
  gap: 10px;
}

.upgrade-actions {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.upgrade-button {
  width: 100%;
  text-align: left;
  background: #173049;
  color: var(--text);
}

.upgrade-button strong {
  display: block;
  color: var(--team-accent);
  text-transform: uppercase;
}

.upgrade-button span {
  display: block;
  margin-top: 4px;
  font-size: 0.8rem;
  color: #d6dfc7;
  text-transform: uppercase;
}

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

.runner-card {
  width: 100%;
  text-align: left;
  border: 3px solid var(--line);
  background: #19324a;
  color: var(--text);
  padding: 12px;
  display: grid;
  gap: 8px;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.14);
}

.runner-card.selected {
  background: linear-gradient(180deg, rgba(226, 187, 79, 0.32), rgba(25, 50, 74, 0.96));
  border-color: var(--team-accent);
}

.runner-card .runner-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}

.runner-card strong {
  font-size: 0.95rem;
  color: var(--team-accent);
  text-transform: uppercase;
}

.runner-card span {
  font-size: 0.72rem;
  color: #d6dfc7;
  text-transform: uppercase;
}

.runner-card .runner-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  font-family: "Trebuchet MS", sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
}

button {
  border: 3px solid var(--line);
  padding: 12px 20px;
  font: inherit;
  font-size: 0.95rem;
  text-transform: uppercase;
  color: #1d1607;
  background: var(--accent);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.16);
  cursor: pointer;
}

button:hover {
  filter: brightness(1.04);
}

button:active {
  transform: translateY(1px);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.16);
}

.secondary-button {
  background: #29445f;
  color: var(--text);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.2);
}

@media (max-width: 980px) {
  .game-shell {
    width: min(100vw - 20px, 920px);
    grid-template-columns: 1fr;
    grid-template-areas:
      "title"
      "play"
      "info";
  }
}

@media (max-width: 640px) {
  .play-panel::before {
    margin-left: -10px;
    margin-right: -10px;
  }

  .play-panel {
    padding: 10px;
  }

  .canvas-frame {
    padding: 8px;
  }

  .franchise-card {
    grid-template-columns: 1fr;
  }

  .season-strip,
  .franchise-dashboard,
  .setup-grid,
  .homepage-actions {
    grid-template-columns: 1fr;
  }
}

body[data-device="tablet"] .game-shell {
  width: calc(100vw - 20px);
  height: 100dvh;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 12px;
  padding: 12px 0 12px;
}

body[data-device="tablet"] .top-title h1 {
  font-size: clamp(2rem, 4.3vw, 3.3rem);
}

body[data-device="tablet"] .play-panel {
  padding: 10px;
}

body[data-device="tablet"] .canvas-frame {
  padding: 8px;
}

body[data-device="tablet"] canvas {
  width: min(100%, calc((100dvh - 140px) * 0.75));
}

body[data-device="tablet"] .homepage {
  width: min(100%, 500px);
}

body[data-device="tablet"] .franchise-dashboard {
  grid-template-columns: 1fr;
}

body[data-device="tablet"] .keyboard-instructions,
body[data-device="mobile"] .keyboard-instructions {
  display: none;
}

body[data-device="tablet"] .touch-instructions,
body[data-device="mobile"] .touch-instructions {
  display: block;
}

body[data-device="laptop"] .game-shell {
  width: min(1420px, calc(100vw - 28px));
  height: 100dvh;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 14px;
  padding: 14px 0 14px;
}

body[data-device="laptop"] .top-title h1 {
  font-size: clamp(2.15rem, 3.4vw, 3.5rem);
}

body[data-device="laptop"] .play-panel {
  padding: 10px;
}

body[data-device="laptop"] .canvas-frame {
  padding: 8px;
}

body[data-device="laptop"] canvas {
  width: auto;
  height: min(100%, calc(100dvh - 132px));
  max-width: 100%;
}

body[data-device="laptop"] .homepage {
  width: min(100%, 520px);
}

body[data-device="laptop"] .franchise-dashboard {
  grid-template-columns: 1fr;
}

body[data-device="mobile"] .game-shell {
  width: calc(100vw - 12px);
  height: 100dvh;
  grid-template-columns: 1fr;
  grid-template-areas:
    "title"
    "play";
  gap: 8px;
  padding: 8px 0;
}

body[data-device="mobile"] .info-panel {
  display: none;
}

body[data-device="mobile"] .top-title h1 {
  font-size: clamp(1.7rem, 7vw, 2.5rem);
  padding: 2px 10px 0;
}

body[data-device="mobile"] .play-panel {
  padding: 8px;
}

body[data-device="mobile"] .play-panel::before {
  margin: -8px -8px 8px;
}

body[data-device="mobile"] .canvas-frame {
  padding: 6px;
}

body[data-device="mobile"] canvas {
  width: auto;
  height: min(100%, calc(100dvh - 120px));
  max-width: 100%;
}

body[data-device="mobile"] .overlay {
  inset: 6px;
  padding: 14px;
}

body[data-device="mobile"] .homepage {
  width: min(100%, 440px);
  gap: 10px;
}

body[data-device="mobile"] .season-strip,
body[data-device="mobile"] .franchise-dashboard,
body[data-device="mobile"] .franchise-card {
  grid-template-columns: 1fr;
}

body[data-device="mobile"] .runner-grid {
  gap: 8px;
}

body[data-device="mobile"][data-orientation="landscape"] .game-shell {
  width: calc(100vw - 10px);
  gap: 6px;
  padding: 6px 0;
}

body[data-device="mobile"][data-orientation="landscape"] .top-title h1 {
  font-size: clamp(1.4rem, 4vw, 2rem);
}

body[data-device="mobile"][data-orientation="landscape"] canvas {
  height: min(100%, calc(100dvh - 76px));
}
