/* Story live mode — mobile first, dark, thumb-reachable controls. */

:root {
  --green: #008d36;
  --blue: #009cde;
  --bg: #101010;
  --surface: #1b1b1b;
  --surface-raised: #262626;
  --border: #333333;
  --text: #f2f2f2;
  --text-muted: #9a9a9a;
  --danger: #e2564a;
  --warn: #e0a32e;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  /* Stops iOS from zooming when a number input is focused. */
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* ------------------------------------------------------------------ header */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(16, 16, 16, 0.94);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar__title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.topbar__title span {
  color: var(--green);
}

.chip {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-height: 40px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  text-align: left;
}

.topbar__action {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  font-size: 13px;
}

.badge-offline {
  flex: 0 0 auto;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--warn);
  color: #101010;
  font-size: 11px;
  font-weight: 700;
}

.status {
  margin: 0;
  padding: 8px 14px;
  font-size: 13px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}

.status[data-kind='ok'] {
  color: var(--green);
}
.status[data-kind='warn'] {
  color: var(--warn);
}
.status[data-kind='error'] {
  color: var(--danger);
}

/* --------------------------------------------------------------- install */

.install {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-raised);
  border-bottom: 1px solid var(--border);
}

.install[hidden] {
  display: none;
}

.install__text {
  flex: 1 1 auto;
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-muted);
}

.install__text b {
  color: var(--text);
  font-weight: 600;
}

.install__action {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--green);
  border-radius: 999px;
  background: var(--green);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
}

.install__action[hidden] {
  display: none;
}

.install__close {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
}

/* ---------------------------------------------------------------- picker */

.screen {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.screen[hidden] {
  display: none;
}

.screen__intro {
  margin: 0;
  padding: 16px 14px 4px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
}

.game-list {
  list-style: none;
  margin: 0;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.game {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 14px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
}

.game:active {
  background: var(--surface-raised);
}

.game.is-loading {
  opacity: 0.5;
}

.game__date {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.game__teams {
  font-size: 15px;
  font-weight: 600;
}

.game__badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-raised);
  color: var(--text-muted);
}

.hint {
  margin: 0;
  padding: 14px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
}

.hint--error {
  color: var(--danger);
}

/* ---------------------------------------------------------------- editor */

.templates {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  border-bottom: 1px solid var(--border);
}

.templates::-webkit-scrollbar {
  display: none;
}

.templates__group {
  flex: 0 0 auto;
  padding: 0 6px 0 10px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.templates__group:first-child {
  padding-left: 0;
}

.template {
  position: relative;
  flex: 0 0 auto;
  /* Kept at a comfortable tap size — this row gets hit repeatedly during a game. */
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  white-space: nowrap;
}

.template[aria-pressed='true'] {
  background: var(--green);
  border-color: var(--green);
  color: #ffffff;
  font-weight: 600;
}

.template__badge {
  margin-left: 6px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--blue);
  color: #ffffff;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.preview {
  display: flex;
  justify-content: center;
  padding: 12px;
}

.preview canvas {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 46vh;
  aspect-ratio: 1080 / 1920;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 4px 14px 16px;
}

.scores {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.score__label,
.field__label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score__controls {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: stretch;
  gap: 6px;
}

.score__step {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-raised);
  font-size: 22px;
  line-height: 1;
  /* Comfortable tap target while wearing gloves in a cold arena. */
  min-height: 52px;
}

.score__step:active {
  background: var(--green);
  border-color: var(--green);
}

.score__input,
.field__input {
  width: 100%;
  min-height: 52px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  /* 16px keeps iOS Safari from zooming the viewport on focus. */
  font-size: 16px;
}

.score__input {
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}

.score__input::-webkit-outer-spin-button,
.score__input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.score__input:focus,
.field__input:focus {
  outline: 2px solid var(--green);
  outline-offset: 1px;
}

/* ---------------------------------------------------------------- actions */

.actions {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background: rgba(16, 16, 16, 0.94);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
}

.action {
  flex: 1 1 0;
  min-height: 52px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-raised);
  font-size: 14px;
  font-weight: 600;
}

.action--primary {
  background: var(--green);
  border-color: var(--green);
  color: #ffffff;
}

.action--video {
  background: var(--blue);
  border-color: var(--blue);
  color: #ffffff;
}

.action--icon {
  flex: 0 0 56px;
}

.action:disabled {
  opacity: 0.5;
}

.action.is-playing {
  background: var(--warn);
  border-color: var(--warn);
  color: #101010;
}

/* ---------------------------------------------------------------- desktop */

@media (min-width: 900px) {
  .screen--editor {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      'templates templates'
      'preview   fields'
      'preview   actions';
    gap: 0 24px;
    padding: 0 24px 24px;
    align-items: start;
  }

  .templates {
    grid-area: templates;
    flex-wrap: wrap;
    overflow: visible;
  }

  .preview {
    grid-area: preview;
  }

  .preview canvas {
    max-height: 72vh;
  }

  .fields {
    grid-area: fields;
  }

  .actions {
    grid-area: actions;
    position: static;
    border: none;
    background: none;
    padding-left: 14px;
    padding-right: 14px;
  }
}
