/* SkiFree layout: Windows 3.1 chrome (win31.css) around a pure white,
   pixel-perfect slope. The play area locks touch gestures (no scroll,
   pull-to-refresh, zoom or text selection). Mobile first; text and
   controls grow with the screen (vmin) up to a 4K TV. */
[hidden] {
  display: none !important;
}

html {
  font-size: clamp(16px, 2.4vmin, 64px);
}

html,
body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  background: #ffffff;
  color: #000000;
}

.game-nav {
  flex: 0 0 auto;
  background: var(--sf-grey);
  border-bottom: 2px solid var(--sf-dark);
  box-shadow: none;
}

.nav-title {
  color: #000000;
  font-family: var(--sf-font);
}

.options-panel-sheet {
  color: #1f2937;
}

.sf-lang-switch {
  display: flex;
  gap: 8px;
}

/* Android bars can cover the bottom even when the safe-area inset is 0:
   nothing essential in the bottom 40px nor in the 24px side strips. */
.sf-app {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  box-sizing: border-box;
  padding: 0 max(24px, env(safe-area-inset-right, 0px))
    max(40px, calc(env(safe-area-inset-bottom, 0px) + 24px))
    max(24px, env(safe-area-inset-left, 0px));
  background: var(--sf-grey);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  font-family: var(--sf-font);
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: unset;
  font-smooth: never;
}

.sf-app [hidden] {
  display: none !important;
}

/* --- Start screen --- */
.sf-start {
  flex: 1;
  min-width: 0;
  display: grid;
  place-items: center;
  padding: 0.5em 0 0;
  background: var(--sf-grey);
  overflow: auto;
}

.sf-start .sf-window {
  box-sizing: border-box;
  width: min(100%, 25em);
}

.sf-logo {
  width: 214px;
  height: 110px;
  margin: 0 auto 10px;
  background: #ffffff url("assets/sprites.png") -116px 0 / 512px 822px no-repeat;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  box-shadow: var(--sf-sunken);
}

.sf-records-title {
  font-weight: 700;
}

.sf-continue {
  display: block;
  min-width: 10em;
  margin: 0 auto 0.5em;
}

.sf-continue-info {
  display: block;
  font-size: 0.8em;
  font-weight: 400;
}

.sf-records {
  margin: 0 0 0.75em;
  padding: 0.4em 0.5em;
  list-style: none;
  background: #ffffff;
  box-shadow: var(--sf-sunken);
  text-align: left;
  font-size: 0.85em;
  line-height: 1.5;
}

/* --- Play stage: board + control bar (below in portrait, right side in
   landscape) --- */
.sf-stage {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.sf-board {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #ffffff;
}

.sf-canvas {
  position: absolute;
  inset: 0;
  display: block;
  background: #ffffff;
  touch-action: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: crosshair;
}

.sf-status {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 9.5em;
  padding: 0.3em 0.45em;
  border: 1px solid #000000;
  background: var(--sf-grey);
  box-shadow: var(--sf-raised);
  font-size: 0.78em;
  font-weight: 700;
  line-height: 1.3;
  pointer-events: none;
}

.sf-status-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  white-space: nowrap;
}

.sf-status-course {
  margin-top: 3px;
  padding-top: 3px;
  border-top: 1px solid var(--sf-dark);
  justify-content: flex-start;
}

.sf-toast {
  position: absolute;
  top: 6px;
  left: 6px;
  max-width: min(60%, 19em);
  pointer-events: none;
}

.sf-toast-text {
  padding: 0.5em 0.6em;
  list-style: none;
  text-align: left;
  font-size: 0.8em;
  line-height: 1.35;
}

.sf-load-error {
  position: absolute;
  left: 50%;
  top: 40%;
  margin: 0;
  padding: 12px;
  transform: translateX(-50%);
}

.sf-controls {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 0.4em;
  padding: 0.4em 0 0;
  background: var(--sf-grey);
  border-top: 2px solid var(--sf-dark);
}

.sf-btn-jump {
  grid-row: 1 / span 2;
  min-height: 5.9em;
  font-size: 1.05em;
}

.sf-controls .sf-btn-turbo {
  grid-column: 2 / span 2;
}

.sf-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 0.5em;
  overflow-y: auto;
}

.sf-dialog {
  box-sizing: border-box;
  width: min(100%, 22em);
}

.sf-dialog .sf-btn {
  display: block;
  width: 100%;
  margin-top: 0.4em;
}

.sf-dialog-actions {
  display: flex;
  gap: 0.4em;
}

.sf-dialog-actions .sf-btn {
  flex: 1 1 0;
  min-width: 0;
}

.sf-dialog-title {
  font-size: 1.25em;
  font-weight: 700;
}

.sf-new-best {
  display: block;
}

.sf-canvas:focus-visible {
  outline: 2px dotted #000000;
  outline-offset: -4px;
}

.sf-best {
  font-weight: 700;
}

@media (orientation: landscape) and (min-width: 560px) {
  .sf-stage {
    flex-direction: row;
  }

  .sf-controls {
    width: max(8.75em, 18vw);
    grid-template-columns: 1fr;
    grid-template-rows: none;
    align-content: center;
    padding: 0 0 0 0.5em;
    border-top: 0;
    border-left: 2px solid var(--sf-dark);
  }

  .sf-btn-jump {
    grid-row: auto;
    min-height: 6.9em;
  }

  .sf-controls .sf-btn-turbo {
    grid-column: auto;
  }
}

/* Landscape phones are ~360px tall: compact start window, side bar and
   dialogs. */
@media (orientation: landscape) and (max-height: 500px) {
  .sf-start .sf-window {
    width: min(100%, 36em);
  }

  .sf-window-body {
    padding: 0.4em 0.75em 0.6em;
  }

  .sf-window-body p {
    margin-bottom: 0.3em;
  }

  .sf-logo,
  .sf-pitch {
    display: none;
  }

  .sf-records {
    columns: 2;
    margin-bottom: 0.4em;
  }

  .sf-btn {
    min-height: 40px;
  }

  .sf-btn-jump {
    min-height: 4.5em;
  }

  .sf-controls {
    gap: 0.25em;
  }
}

/* Desktop and TV, 960x540 up to 3840x2160: the header grows with the
   screen and everything stays 3% away from the edges (TV overscan). */
@media (min-width: 960px) and (min-height: 500px) {
  .game-nav {
    height: auto;
    padding: 3dvh max(3vw, env(safe-area-inset-right, 0px)) 1dvh
      max(3vw, env(safe-area-inset-left, 0px));
  }

  .nav-title {
    font-size: max(1.1rem, 3.4dvh);
  }

  .back-button,
  .options-button {
    width: max(36px, 6dvh);
    height: max(36px, 6dvh);
    font-size: max(1rem, 3dvh);
  }

  .back-button svg,
  .options-button svg {
    width: 50%;
    height: 50%;
  }

  .sf-app {
    padding: 2dvh max(3vw, env(safe-area-inset-right, 0px)) max(40px, 4dvh)
      max(3vw, env(safe-area-inset-left, 0px));
  }

  .sf-start .sf-window {
    width: min(100%, 30em);
  }

  .sf-logo {
    transform: scale(1.5);
    margin: 28px auto 38px;
  }
}

/* TV remote: a thick, high-contrast ring on the focused control. */
html.tv :focus {
  outline: 0.3rem solid #000080 !important;
  outline-offset: 0.2rem;
  box-shadow: 0 0 0 0.6rem rgba(255, 255, 0, 0.9);
}
