/* Der Aal - styles
 * Colours come from the drawing: river blue, eel olive, belly cream,
 * roach-fin orange. Cards look like soft paper floating on the water.
 */

@font-face {
  font-family: 'Fredoka';
  src: url('assets/fonts/fredoka-latin.woff2') format('woff2');
  font-weight: 300 700;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Fredoka';
  src: url('assets/fonts/fredoka-latin-ext.woff2') format('woff2');
  font-weight: 300 700;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --wasser: #123f66;
  --wasser-tief: #0b2a47;
  --papier: #fbf5e6;
  --papier-rand: #e8dcbc;
  --tinte: #1f2b26;
  --tinte-hell: #56625a;
  --oliv: #6b7a2b;
  --oliv-dunkel: #3b4614;
  --sand: #e9dd9f;
  --flosse: #e2603a;
  --sonne: #f6b73c;
  --sonne-dunkel: #b97a12;
  --schatten: rgba(8, 24, 40, 0.35);
  --radius: 22px;
  --font: 'Fredoka', 'Trebuchet MS', system-ui, sans-serif;
  --hud-height: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--wasser-tief);
  color: var(--tinte);
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.35;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.field {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Swipe area, active only while playing */
.touch {
  position: absolute;
  inset: 0;
  touch-action: none;
  display: none;
}
.app[data-mode='play'] .touch { display: block; }

[hidden] { display: none !important; }

/* ---------------------------------------------------------------- HUD */

.hud {
  position: absolute;
  top: var(--safe-top);
  left: 0;
  right: 0;
  height: var(--hud-height);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 max(12px, env(safe-area-inset-right, 0px)) 0 max(12px, env(safe-area-inset-left, 0px));
  pointer-events: none;
  z-index: 3;
}
.hud > * { pointer-events: auto; }

.hud-box {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 14px;
  background: rgba(251, 245, 230, 0.92);
  border: 3px solid var(--oliv-dunkel);
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--oliv-dunkel);
}
.hud-label { font-size: 0.75rem; color: var(--tinte-hell); text-transform: uppercase; letter-spacing: 0.05em; }
.hud-value { font-size: 1.35rem; font-weight: 700; min-width: 2ch; font-variant-numeric: tabular-nums; }
.hud-section {
  margin-left: auto;
  color: var(--papier);
  font-weight: 600;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}

.round-button {
  width: 48px;
  height: 48px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 3px solid var(--oliv-dunkel);
  background: var(--papier);
  box-shadow: 0 3px 0 var(--oliv-dunkel);
  color: var(--oliv-dunkel);
  cursor: pointer;
  padding: 0;
}
.round-button svg { width: 24px; height: 24px; fill: currentColor; }
.round-button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--oliv-dunkel); }

.toast {
  position: absolute;
  top: calc(var(--safe-top) + var(--hud-height) + 12px);
  left: 50%;
  transform: translate(-50%, -8px);
  padding: 6px 18px;
  border-radius: 999px;
  background: var(--sonne);
  border: 3px solid var(--sonne-dunkel);
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 4;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------------------- Screens */

.screen {
  position: absolute;
  inset: 0;
  display: grid;
  /* One column exactly as wide as the screen, so long texts wrap instead
     of pushing the card past the edge. */
  grid-template-columns: minmax(0, 1fr);
  /* Centred when the card fits; starts at the top (and scrolls) when it
     is taller than the screen, so nothing is cut off above. */
  place-items: start center;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  overflow-y: auto;
  z-index: 5;
  background: rgba(6, 24, 42, 0.35);
}

.card {
  margin-block: auto;
  width: min(520px, 100%);
  background: var(--papier);
  border: 4px solid var(--oliv-dunkel);
  border-radius: var(--radius);
  box-shadow: 0 8px 0 var(--oliv-dunkel), 0 18px 40px var(--schatten);
  padding: 22px 24px 20px;
  text-align: center;
}
.card-small { width: min(380px, 100%); }
.card > * + * { margin-top: 14px; }

h2 { margin: 0; font-size: 1.8rem; color: var(--oliv-dunkel); }

.logo {
  margin: 0;
  font-size: clamp(2.6rem, 9vw, 3.8rem);
  font-weight: 700;
  line-height: 1;
  color: var(--oliv);
  letter-spacing: 0.01em;
  text-shadow: 0 3px 0 var(--oliv-dunkel), 0 6px 0 rgba(59, 70, 20, 0.25);
}
.tagline { margin-top: 8px; color: var(--tinte-hell); }

/* ------------------------------------------------------------- Buttons */

.button {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 10px 18px;
  border: 3px solid var(--oliv-dunkel);
  border-radius: 16px;
  background: var(--papier);
  color: var(--oliv-dunkel);
  font: 600 1.1rem/1.2 var(--font);
  box-shadow: 0 4px 0 var(--oliv-dunkel);
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
}
.button:hover { background: #fffbef; }
.button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--oliv-dunkel); }

.button-start {
  min-height: 60px;
  font-size: 1.6rem;
  font-weight: 700;
  background: var(--sonne);
  border-color: var(--sonne-dunkel);
  color: #3a2504;
  box-shadow: 0 5px 0 var(--sonne-dunkel);
}
.button-start:hover { background: #ffc552; }
.button-start:active { box-shadow: 0 2px 0 var(--sonne-dunkel); }

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

.link-button {
  border: 0;
  background: none;
  padding: 0 0 0 4px;
  font: inherit;
  font-weight: 700;
  color: var(--oliv-dunkel);
  text-decoration: underline;
  cursor: pointer;
}

:focus-visible {
  outline: 4px solid #2f7fd0;
  outline-offset: 3px;
}

/* ------------------------------------------------------ Section choice */

.sections {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 18px;
}
.section-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 56px;
  padding: 6px 4px;
  border: 3px solid var(--papier-rand);
  border-radius: 14px;
  background: #f3ecd8;
  color: var(--tinte);
  font: 600 1rem/1.1 var(--font);
  cursor: pointer;
}
.section-chip[aria-pressed='true'] {
  border-color: var(--oliv-dunkel);
  background: var(--sand);
  box-shadow: inset 0 -3px 0 rgba(59, 70, 20, 0.25);
}
.section-chip:disabled { cursor: not-allowed; color: #9a9584; background: #efe9d8; }
.chip-info { font-size: 0.75rem; font-weight: 400; color: var(--tinte-hell); }
.section-chip:disabled .chip-info { color: #a39d8a; }
.chip-info svg { width: 0.8em; height: 0.8em; vertical-align: -0.05em; fill: currentColor; }

/* ------------------------------------------------------------ Switches */

.switches { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px; }
.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  border: 0;
  background: none;
  color: var(--tinte);
  font: 500 0.95rem var(--font);
  cursor: pointer;
  padding: 0 4px;
}
.switch-track {
  position: relative;
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: #cfc6ad;
  border: 2px solid var(--oliv-dunkel);
  transition: background 0.15s;
}
.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--papier);
  border: 2px solid var(--oliv-dunkel);
  transition: transform 0.15s;
}
.switch[aria-checked='true'] .switch-track { background: var(--oliv); }
.switch[aria-checked='true'] .switch-thumb { transform: translateX(20px); }

.storage-hint {
  font-size: 0.85rem;
  color: var(--tinte-hell);
  background: #f3ecd8;
  border-radius: 12px;
  padding: 8px 12px;
}

.title-links {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
}
.title-links a { color: var(--oliv-dunkel); }
.back-link { font-weight: 600; }
.back-link::before { content: '← '; }
.legal { display: flex; gap: 12px; }
.legal a { color: var(--tinte-hell); }

/* ---------------------------------------------------------------- Help */

.help-list {
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
  text-align: left;
  display: grid;
  gap: 12px;
}
.help-list li { display: flex; align-items: center; gap: 14px; }
.help-pic {
  flex: none;
  width: 64px;
  height: 44px;
  border-radius: 10px;
  background: var(--wasser);
}
.help-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; align-content: center; padding: 0 4px; }
kbd {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 4px;
  border-radius: 5px;
  background: var(--papier);
  color: var(--oliv-dunkel);
  font: 700 0.75rem var(--font);
  box-shadow: 0 2px 0 #9f9576;
}

/* --------------------------------------------------------- Leaderboard */

.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tab {
  min-height: 44px;
  border: 3px solid var(--papier-rand);
  border-radius: 12px;
  background: #f3ecd8;
  font: 600 1rem var(--font);
  color: var(--tinte);
  cursor: pointer;
}
.tab[aria-selected='true'] { border-color: var(--oliv-dunkel); background: var(--sand); }

.muted { color: var(--tinte-hell); }

/* ------------------------------------------- Keyboard hints (desktop) */

.key-hints, .key-hint-line { display: none; }
@media (hover: hover) and (pointer: fine) {
  .key-hints {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px 16px;
    font-size: 0.8rem;
    color: var(--tinte-hell);
  }
  .key-hints span { display: inline-flex; align-items: center; gap: 3px; }
  .key-hint-line { display: block; font-size: 0.85rem; color: var(--tinte-hell); }
}
.key-hints kbd, .key-hint-line kbd { box-shadow: 0 2px 0 #b5ab8c; border: 1px solid #cfc5a6; }
kbd.wide { padding: 0 8px; }

.fullscreen-button .icon-exit { display: none; }
.is-fullscreen .fullscreen-button .icon-enter { display: none; }
.is-fullscreen .fullscreen-button .icon-exit { display: block; }

/* While playing with a mouse, the pointer hides after a moment of rest. */
.app.cursor-hidden, .app.cursor-hidden * { cursor: none !important; }

/* ------------------------------------------------------ Ready / Over */

.overlay {
  position: absolute;
  inset: auto 0 calc(24px + var(--safe-bottom)) 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 4;
  padding: 0 16px;
}
.bubble {
  margin: 0;
  max-width: 460px;
  padding: 10px 20px;
  border-radius: 18px;
  background: rgba(251, 245, 230, 0.94);
  border: 3px solid var(--oliv-dunkel);
  font-weight: 600;
  text-align: center;
  animation: bob 2.4s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(-6px); } }
.bubble p { margin: 0; }
.ready-hint { margin-top: 4px !important; font-weight: 400; font-size: 0.85rem; color: var(--tinte-hell); }

/* ---------------------------------------------------------------- End */

.card-over { width: min(440px, 100%); }
.card-over > * + * { margin-top: 10px; }
.over-eel { display: block; width: 220px; height: 150px; margin: -6px auto 0; }
.over-score { font-size: 2.4rem; font-weight: 700; color: var(--oliv-dunkel); margin-bottom: 0; line-height: 1.1; }
.over-score span { font-variant-numeric: tabular-nums; }
.over-stats {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--tinte-hell);
}
.over-stats li { background: #f3ecd8; border-radius: 999px; padding: 2px 10px; }
.over-stats span { font-weight: 700; color: var(--tinte); }
.over-note { color: var(--tinte); font-weight: 600; min-height: 1.35em; }
.over-note.unlock { color: #8a4b00; }
.over-buttons { margin-top: 14px !important; }

.name-form {
  background: #f3ecd8;
  border: 3px dashed var(--sonne-dunkel);
  border-radius: 16px;
  padding: 12px 14px;
  text-align: left;
}
.name-form > * + * { margin-top: 6px; }
.name-form p { margin: 0; }
.name-title { font-weight: 700; color: #8a4b00; text-align: center; }
.name-label { display: block; font-size: 0.85rem; color: var(--tinte-hell); }
.name-row { display: flex; gap: 8px; }
.name-row input {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 6px 12px;
  border: 3px solid var(--oliv-dunkel);
  border-radius: 12px;
  background: #fff;
  color: var(--tinte);
  font: 600 1.1rem var(--font);
  user-select: text;
  -webkit-user-select: text;
}
.button-send { width: auto; flex: none; }
.name-message { min-height: 1.2em; font-size: 0.9rem; font-weight: 600; color: #a1361f; }
.name-message.ok { color: #2f6b22; }
.name-privacy { font-size: 0.75rem; color: var(--tinte-hell); }
.scores-offline { font-size: 0.85rem; color: var(--tinte-hell); }

/* -------------------------------------------------------- Leaderboard */

.score-list { min-height: 200px; max-height: min(52vh, 560px); overflow-y: auto; }
.score-table { list-style: none; margin: 0; padding: 0; width: 100%; text-align: left; }
.score-table li {
  display: grid;
  grid-template-columns: 2.4em 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 10px;
}
.score-table li:nth-child(odd) { background: #f3ecd8; }
.score-table li.mine { background: var(--sand); outline: 3px solid var(--sonne-dunkel); }
.score-rank {
  display: grid;
  place-items: center;
  width: 1.9em;
  height: 1.9em;
  border-radius: 50%;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--tinte-hell);
}
.score-table li:nth-child(1) .score-rank { background: #f6c945; color: #4a3300; }
.score-table li:nth-child(2) .score-rank { background: #d5d9dc; color: #2f3539; }
.score-table li:nth-child(3) .score-rank { background: #d99b62; color: #3e2410; }
.score-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-points { font-weight: 700; font-variant-numeric: tabular-nums; }
.score-empty { align-self: center; }
.own-best { font-size: 0.9rem; color: var(--tinte-hell); min-height: 1.2em; }

.noscript { position: absolute; inset: 40% 16px auto; text-align: center; color: var(--papier); }

/* ------------------------------------------------- Small and low screens */

@media (max-width: 420px) {
  html, body { font-size: 16px; }
  .card { padding: 18px 16px 16px; }
  .hud-box { padding: 2px 10px; }
  .hud-section { display: none; }
}

/* Phones held sideways: two columns so the title fits without scrolling */
@media (max-height: 520px) and (orientation: landscape) {
  html, body { font-size: 16px; }
  .screen { padding-top: calc(8px + var(--safe-top)); padding-bottom: calc(8px + var(--safe-bottom)); }
  .card { padding: 14px 18px 12px; box-shadow: 0 5px 0 var(--oliv-dunkel), 0 12px 30px var(--schatten); }
  .card > * + * { margin-top: 10px; }
  .card-title {
    width: min(780px, 100%);
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    gap: 8px 22px;
    align-items: center;
    text-align: left;
  }
  .card-title > * + * { margin-top: 0; }
  .card-title .logo { grid-column: 1; grid-row: 1; font-size: 2.4rem; }
  .card-title .tagline { grid-column: 1; grid-row: 2; margin: 0; font-size: 0.9rem; }
  .card-title .sections { grid-column: 1; grid-row: 3; margin: 0; }
  .card-title .switches { grid-column: 1; grid-row: 4; justify-content: flex-start; gap: 0 12px; }
  .card-title .button-start { grid-column: 2; grid-row: 1 / span 2; min-height: 56px; }
  .card-title .button-row { grid-column: 2; grid-row: 3; }
  .card-title .title-links { grid-column: 2; grid-row: 4; }
  .card-title .storage-hint { grid-column: 1 / -1; grid-row: 5; padding: 4px 10px; font-size: 0.8rem; }
  .section-chip { min-height: 48px; }
  .chip-info { font-size: 0.7rem; }
  .button { min-height: 44px; padding: 6px 14px; }
  .help-list { gap: 4px; font-size: 0.85rem; margin-top: 8px; }
  .help-pic { width: 52px; height: 36px; }
  .card-over { width: min(760px, 100%); display: grid; grid-template-columns: 230px 1fr; gap: 4px 20px; align-items: center; }
  .card-over > * { margin-top: 0 !important; }
  .card-over .over-eel { grid-column: 1; grid-row: 1; width: 150px; height: 100px; margin: 0 auto; }
  .card-over h2 { grid-column: 1; grid-row: 2; font-size: 1.25rem; }
  .card-over .over-score { grid-column: 1; grid-row: 3; font-size: 1.8rem; }
  .card-over .over-stats { grid-column: 1; grid-row: 4; }
  .card-over .over-note { grid-column: 1; grid-row: 5; font-size: 0.85rem; }
  .card-over .name-form { grid-column: 2; grid-row: 1 / span 3; padding: 8px 12px; }
  .card-over .scores-offline, .card-over #show-scores { grid-column: 2; grid-row: 2; }
  .card-over .over-buttons { grid-column: 2; grid-row: 4 / span 2; }
  .card-over .key-hint-line { display: none; }
  .name-row input { min-height: 44px; }
  .name-privacy { display: none; }
  .score-list { max-height: 48vh; }
}

/* Score column on the left for flat landscape screens (set by game.js) */
.app.hud-side .hud {
  top: 0;
  bottom: 0;
  right: auto;
  width: 112px;
  height: auto;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  padding: calc(8px + var(--safe-top)) 8px calc(8px + var(--safe-bottom)) max(8px, env(safe-area-inset-left, 0px));
}
.app.hud-side .hud-box { flex-direction: column; align-items: center; gap: 0; border-radius: 16px; padding: 2px 8px 4px; }
.app.hud-side .hud-section { margin: 0; text-align: center; display: block; }
.app.hud-side .round-button { align-self: center; }
.app.hud-side .toast { top: 12px; left: calc(50% + 56px); }

/* Big monitors and boards: everything a bit larger */
@media (min-width: 1600px) and (min-height: 900px) {
  html, body { font-size: 21px; }
  :root { --hud-height: 64px; }
  .card { width: min(600px, 100%); }
  .round-button { width: 54px; height: 54px; }
}

/* Less motion: no bobbing, no sliding */
.reduced-motion *, .reduced-motion *::before, .reduced-motion *::after {
  animation: none !important;
  transition: none !important;
}
