/* PlaySHS — homepage, episode library and player */

:root {
  --site-width: 480px;
  --ink: #285ca7;
  --panel-border: #4c7cd0;
  --paper: linear-gradient(120deg, #fffefdf5, #f0f1eef5);
  --wood: url("./wood.png");
  --surface: #fffefa;
  --muted: #506885;
  --radius: 12px;
  --shadow: 0 3px 10px #16345b22;

  --nav-top: max(10px, env(safe-area-inset-top));
  --nav-left: max(14px, env(safe-area-inset-left));
  --nav-right: max(14px, env(safe-area-inset-right));
  --nav-logo-size: 56px;
  --nav-height: calc(var(--nav-top) + var(--nav-logo-size));
}

/* Base */

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

html {
  color-scheme: light;
  background: #24170f;
}

html,
body {
  height: 100vh;
  height: var(--viewport-height, 100dvh);
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  margin: 0;
  color: var(--ink);
  font: 16px/1.5 "Trebuchet MS", Arial, sans-serif;
  background: #1e1e1e;
}

button,
input,
a {
  font: inherit;
}

button {
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

button,
a,
input,
label {
  touch-action: manipulation;
}

button:disabled {
  opacity: .45;
  cursor: default;
}

a {
  color: inherit;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
.file-button:focus-within,
#episode-viewport:focus-visible {
  outline: 3px solid #245896;
  outline-offset: 3px;
}

h1,
h2,
p {
  margin-top: 0;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Shared fixed page dimensions */

.site-shell,
#player {
  position: fixed;
  top: 0;
  left: 50%;
  width: var(--shell-width, min(100%, var(--site-width)));
  height: var(--shell-height, 100dvh);
  min-height: 0;
  margin: 0;
  overflow: hidden;
  transform: translateX(-50%) scale(var(--shell-scale, 1));
  transform-origin: top center;
  background: var(--wood) center top / 100% auto;
  box-shadow: 0 0 70px #0009;
}

/* Homepage */

.home-shell {
  display: grid;
  grid-template-rows: minmax(0, .36fr) minmax(0, 1fr) auto;
  justify-items: center;
  align-items: stretch;
  padding:
    max(16px, env(safe-area-inset-top))
    0
    max(16px, env(safe-area-inset-bottom));
}

.home-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 2;
  width: 41%;
  height: 100%;
  min-height: 0;
  margin: 0;
  line-height: 0;
  transform: rotate(-4deg);
}

.home-brand img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
  filter: drop-shadow(1px 5px 3px #45250985);
}

.home-photo {
  display: block;
  width: 109%;
  height: 100%;
  min-height: 0;
  max-width: none;
  margin: 0;
  object-fit: contain;
  pointer-events: none;
}

.home-tabs {
  position: relative;
  z-index: 3;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 0 8%;
}

.yellow-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  width: 90%;
  padding: 8px 12px;
  color: #574017;
  text-align: center;
  font-size: clamp(18px, 5vw, 24px);
  line-height: 1.15;
  font-weight: 900;
  font-style: italic;
  text-transform: uppercase;
  text-decoration: none;
  letter-spacing: .5px;
  text-shadow: 0 1px #fff3bd, 1px 2px #c39a35;
  border: 2px solid #db9d23;
  border-radius: 11px;
  background: linear-gradient(
    #fffbc8 0%,
    #ffe98c 20%,
    #ffc935 60%,
    #f6b41c 95%
  );
  box-shadow:
    inset 0 0 0 2px #fff2a67a,
    0 4px 5px #4c260d9c;
}

.yellow-tab:nth-child(1) {
  align-self: flex-start;
}

.yellow-tab:nth-child(2) {
  align-self: flex-end;
}

.yellow-tab:nth-child(3) {
  align-self: center;
}

.coming-soon {
  cursor: default;
}

/* Shared menu and logo positioning */

.site-nav,
.player-chrome {
  display: flex;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  align-items: flex-start;
  justify-content: space-between;
  padding: var(--nav-top) var(--nav-right) 0 var(--nav-left);
  pointer-events: none;
}

.site-nav .menu-toggle,
.player-chrome .menu-toggle,
.site-logo {
  pointer-events: auto;
}

.menu-toggle {
  position: relative;
  display: block;
  width: 44px;
  height: 44px;
  flex: none;
  padding: 0;
  border: 2px solid var(--panel-border);
  border-radius: 9px;
  background: #fffefbf2;
  color: var(--ink);
  box-shadow: 0 2px 6px #32160355;
}

.menu-toggle::before,
.menu-toggle::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 20px;
  height: 3px;
  border-radius: 3px;
  background: currentColor;
  transform: translateX(-50%);
  pointer-events: none;
}

.menu-toggle::before {
  top: 13px;
  box-shadow: 0 7px 0 currentColor;
}

.menu-toggle::after {
  top: 27px;
}

.site-logo,
.player-logo {
  display: block;
  width: var(--nav-logo-size);
  height: var(--nav-logo-size);
  flex: none;
  object-fit: contain;
  line-height: 0;
}

.site-logo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.site-logo img,
.player-logo {
  filter: drop-shadow(0 2px 3px #0006);
}

/* Episode library */

.library-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  padding:
    calc(var(--nav-height) + 12px)
    14px
    max(12px, env(safe-area-inset-bottom));
}

.current-episode {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0 12px;
  align-items: center;
  padding: 12px;
  margin: 0 0 12px;
  border: 3px solid var(--panel-border);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.current-episode h1 {
  grid-column: 1;
  margin: 0 0 4px;
  color: #577cad;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  line-height: 1.4;
}

.current-title {
  grid-column: 1;
  display: block;
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.current-empty {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--ink);
  font-size: 13px;
}

.resume-button {
  grid-column: 2;
  grid-row: 1 / span 2;
  width: 86px;
  min-height: 44px;
  margin: 0;
  padding: 6px;
  border: 2px solid var(--panel-border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  line-height: 1.3;
  font-weight: 800;
}

/* Horizontally scrolling seasons */

.season-picker {
  min-width: 0;
  margin-bottom: 10px;
}

.section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 2px 5px;
  color: #fff;
  text-shadow: 0 1px 3px #3b1b09;
  font-weight: 700;
  font-size: 12px;
}

.section-label span {
  font-weight: normal;
  font-size: 11px;
}

#seasons {
  position: relative;
  display: flex;
  gap: 7px;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  touch-action: pan-x;
  padding: 6px;
  border: 3px solid var(--panel-border);
  border-radius: 11px;
  background: var(--paper);
  scrollbar-width: thin;
  scrollbar-color: #7b9fd7 transparent;
  scroll-padding-inline: 6px;
}

#seasons button {
  flex: none;
  white-space: nowrap;
  min-height: 40px;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid #a9bdd8;
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

#seasons button[aria-pressed="true"] {
  border-color: #245ba9;
  background: #326bbe;
  color: #fff;
}

#seasons button:focus-visible {
  outline-offset: -4px;
}

/* Vertically scrolling episode list */

.episode-library {
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  padding: 12px 10px 10px;
  border: 3px solid var(--panel-border);
  border-radius: var(--radius);
  background: var(--paper);
}

.collection-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 8px;
  color: var(--ink);
}

.collection-line h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.3;
  letter-spacing: -.5px;
}

.collection-line span {
  color: #577cad;
  font-size: 11px;
  white-space: nowrap;
}

.search-label {
  display: block;
  width: 100%;
  margin-bottom: 10px;
}

#search {
  width: 100%;
  min-height: 38px;
  padding: 6px 10px;
  border: 1px solid #9bb1cf;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
}

#search::placeholder {
  color: #647a98;
}

#episode-viewport {
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #7b9fd7 transparent;
  border-top: 1px solid #bcc1c7;
  padding-top: 8px;
}

.episode-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-auto-rows: max-content;
  align-content: start;
  gap: 8px;
  margin: 0;
  padding: 3px;
  min-width: 0;
}

.episode-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 58px;
  padding: 11px 12px;
  text-align: left;
  border: 2px solid #6490da;
  border-radius: 7px;
  background: linear-gradient(110deg, #fffefc, #f3f4f2);
  color: var(--ink);
  box-shadow: 0 1px 3px #285ca718;
}

.episode-card[aria-current="true"] {
  border-color: #2e5fb0;
  background: #e9f1ff;
}

.episode-label {
  display: block;
  flex: 1;
  min-width: 0;
}

.episode-title {
  display: block;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.episode-meta {
  display: block;
  margin-top: 4px;
  color: #577cad;
  font-size: 11px;
  line-height: 1.3;
}

.episode-arrow {
  flex: none;
  color: #577cad;
  font-size: 23px;
  line-height: 1;
}

.empty-state {
  margin: 0;
  padding: 12px;
  color: var(--ink);
  font-size: 14px;
}

/* Menus, confirmations and About Us */

dialog {
  width: min(410px, calc(var(--shell-width, 100vw) - 32px));
  max-width: none;
  max-height: calc(var(--shell-height, 100dvh) - 24px);
  overflow-y: auto;
  color: var(--ink);
  border: 3px solid var(--panel-border);
  background: var(--surface);
  border-radius: 13px;
  padding: 20px;
  font: 16px/1.5 "Trebuchet MS", Arial, sans-serif;
  box-shadow: 0 16px 65px #1e120c99;
  transform: scale(var(--shell-scale, 1));
  transform-origin: center;
}

dialog::backdrop {
  background: #102138ad;
}

.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 15px;
}

.dialog-heading h2 {
  margin: 0;
  font-size: 21px;
  line-height: 1.2;
}

.dialog-heading button {
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid #91afd5;
  border-radius: 7px;
  background: #edf3fc;
  color: var(--ink);
}

dialog > button,
dialog > .file-button,
.menu-link {
  display: block;
  width: 100%;
  min-height: 44px;
  margin: 10px 0;
  padding: 10px 12px;
  border: 1px solid #91afd5;
  border-radius: 7px;
  background: #edf3fc;
  color: var(--ink);
  text-align: center;
  text-decoration: none;
  font-size: 15px;
  cursor: pointer;
}

dialog p {
  margin: 16px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

dialog .confirm-destructive {
  background: #285ca7;
  border-color: #285ca7;
  color: #fff;
  font-weight: 700;
}

dialog .confirm-warning {
  font-size: 12px;
}

#episode-confirm-message {
  font-size: 15px;
  color: var(--ink);
}

#menu-status:empty {
  display: none;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

/* Site notifications */

#toast {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  max-width: min(90%, 440px);
  border: 2px solid var(--panel-border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 10px 16px;
  z-index: 50;
  font-size: 14px;
  box-shadow: 0 5px 25px #0005;
  pointer-events: none;
}

#toast:empty {
  display: none;
}

/* Episode player */

#player {
  z-index: 20;
  background: #000;
}

.game-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
}

#stage {
  position: relative;
  isolation: isolate;
  width: 100%;
  height: 100%;
  min-width: 0;
  margin: 0;
  background: #000;
  overflow: hidden;
  container-type: inline-size;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

#stage input {
  -webkit-user-select: text;
  user-select: text;
}

#game-content {
  position: absolute;
  inset: 0;
}

#game-content > canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}

#game-content[aria-busy="true"] {
  cursor: progress;
}

/* Score up and other in-game notices */

#notice {
  position: absolute;
  top: max(72px, calc(env(safe-area-inset-top) + 64px));
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 40px);
  min-height: 46px;
  padding: 12px 20px;
  z-index: 8;
  text-align: center;
  border: 2px solid var(--panel-border);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--surface);
  font-size: clamp(15px, 4.6cqw, 18px);
  font-weight: 700;
  line-height: 1.4;
  overflow-wrap: anywhere;
  white-space: pre-line;
  box-shadow: 0 5px 18px #10203933;
  pointer-events: none;
}

#notice:empty {
  display: none;
}

/* Transparent story and choice hit areas */

.story-controls {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.story-controls button {
  position: absolute;
  pointer-events: auto;
  padding: 0;
  color: transparent;
  background: transparent;
  border: 0;
  border-radius: 1px;
}

.story-controls button:focus-visible,
.football-target:focus-visible,
.football-continue:focus-visible,
.grid-continue:focus-visible {
  outline-offset: -3px;
}

.continue-hit {
  width: 100%;
  height: 100%;
  inset: 0;
}

/* Player loading, setup and message screens */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 70px 20px max(24px, env(safe-area-inset-bottom));
  color: var(--ink);
  text-align: center;
  overflow: auto;
  background: linear-gradient(#f9fbffed, #eaf1fbf5);
}

.overlay h2 {
  font-size: clamp(20px, 7cqw, 32px);
  line-height: 1.2;
  color: var(--ink);
  margin: 10px 0;
}

.overlay p {
  font-size: clamp(16px, 5cqw, 22px);
  white-space: pre-wrap;
}

.overlay button {
  margin: 7px 0;
  padding: .6rem .95rem;
  font-weight: 700;
  background: var(--ink);
  color: #fff;
  border: 2px solid var(--panel-border);
  border-radius: 8px;
  min-height: 44px;
}

.overlay img.cover-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: -1;
  opacity: .65;
}

.overlay .small {
  font-size: 13px;
  color: var(--muted);
}

.overlay input {
  width: 100%;
  border: 1px solid #91afd5;
  border-radius: 8px;
  padding: .7rem 1rem;
  background: #fff;
  color: var(--ink);
  margin: 12px 0;
  font-size: 20px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #285ca733;
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 15px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.picker-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.picker-grid button {
  background: var(--surface);
  border-color: #91afd5;
}

.picker-grid button[aria-pressed="true"] {
  outline: 3px solid var(--ink);
  background: #e9f1ff;
}

.picker-grid img {
  height: 95px;
  max-width: 90px;
  object-fit: contain;
}

.offline-panel {
  background: var(--surface);
}

.offline-panel p {
  font-size: clamp(14px, 4.7cqw, 19px);
  line-height: 1.5;
}

.offline-panel button {
  border: 2px solid var(--panel-border);
  background: #edf3fc;
  color: var(--ink);
  min-height: 44px;
}

/* Football */

.football-panel {
  position: absolute;
  inset: 0;
  color: #fff;
  background: #254e23;
  overflow: hidden;
}

.football-field {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.football-hud {
  position: absolute;
  top: calc(var(--nav-height) + 8px);
  left: 3.125%;
  width: 75.9375%;
  height: auto;
  pointer-events: none;
}

.football-board {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.football-target {
  position: absolute;
  min-width: 0;
  min-height: 0;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 2px;
  pointer-events: auto;
}

.football-continue,
.grid-continue {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: transparent;
}

/* Grid minigames */

.grid-game {
  position: absolute;
  inset: 0;
  display: block;
  padding: 0;
  overflow: hidden;
  background: #fff;
  color: #fff;
}

.grid-backdrop,
.grid-field,
.grid-controls {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.grid-scene {
  position: absolute;
  top: calc(var(--nav-height) + 8px);
  right: 0;
  bottom: env(safe-area-inset-bottom);
  left: 0;
  width: 100%;
  overflow: hidden;
}

.grid-field,
.grid-backdrop {
  display: block;
  pointer-events: none;
}

.grid-controls {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.grid-cell {
  position: absolute;
  display: block;
  margin: 0;
  padding: 0;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: transparent;
  touch-action: none;
}

.grid-cell:disabled {
  opacity: 1;
}

.grid-cell:focus-visible {
  outline: 3px solid var(--panel-border);
  outline-offset: -3px;
}

.grid-description,
.grid-status {
  margin: 0;
  padding: 0;
}

/* Hover effects only for mouse devices */

@media (hover: hover) and (pointer: fine) {
  .home-tabs a[href]:hover,
  .home-tabs button:hover {
    filter: brightness(1.06);
  }

  .episode-card:hover {
    background: #edf3fc;
    border-color: #2e5fb0;
  }

  .menu-toggle:hover,
  #seasons button:hover,
  dialog > button:hover,
  dialog > .file-button:hover,
  .menu-link:hover,
  .dialog-heading button:hover,
  .resume-button:hover {
    background: #dce9fb;
  }

  #seasons button[aria-pressed="true"]:hover,
  dialog .confirm-destructive:hover {
    background: #245ba9;
  }
}