:root{
  --bg:#0f1120;
  --text:#e9edf6;
  --muted:#9aa7c7;
  --tile-size: 86px;
  --gap: 12px;

  /* Skin-muuttujat (ylikirjoitetaan html[data-skin=...] -selektoreilla) */
  --bg-grad: radial-gradient(1200px 800px at 20% -10%, #1f2350 0%, #0f1120 60%);
  --panel-bg: rgba(23,26,43,.6);
  --panel-border: rgba(255,255,255,.08);
  --btn-bg: #242842;
  --tile-base: #303654;
  --tile-shadow: 0 16px 28px rgba(0,0,0,.45), 0 2px 0 rgba(255,255,255,.08) inset, 0 -12px 20px rgba(0,0,0,.35) inset;
}

*{ box-sizing:border-box; }
html, body {
  height: 100%;
  overflow: hidden;
}
body{
  margin:0;
  overflow: hidden;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  background: var(--bg-grad);
  color: var(--text);
}

/* —— Game shell (tablet-friendly: no page scroll; overlays scroll independently) —— */
.app-shell {
  --shell-header-h: 92px;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}
.top-chrome {
  flex-shrink: 0;
  position: relative;
  z-index: 200;
  background: var(--bg-grad);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.22);
}
.top-chrome-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 20px 12px;
}
.top-chrome .top-chrome-inner {
  border: none !important;
  border-image: none !important;
  box-shadow: none !important;
}
html[data-skin="christmas"] .top-chrome .top-chrome-inner,
html[data-skin="classical"] .top-chrome .top-chrome-inner,
html[data-skin="metal"] .top-chrome .top-chrome-inner,
html[data-skin="summer"] .top-chrome .top-chrome-inner {
  padding: 20px 20px 12px;
}
.board-frame {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
}
.board-frame > .main-stage {
  flex: 1 1 auto;
  align-self: stretch;
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.main-stage .board-viewport {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  width: 100%;
}
/* When the grid cannot fit at min tile size, scroll the board instead of clipping tiles */
.main-stage .board-viewport.melody-board-scroll-fallback {
  overflow-x: hidden;
  overflow-y: auto;
  align-items: flex-start;
  justify-content: center;
  -webkit-overflow-scrolling: touch;
}
.main-stage .board-viewport.melody-board-scroll-fallback .melody-area-wrap {
  max-height: none;
  flex-shrink: 0;
}
.main-stage .board-viewport.melody-board-scroll-fallback .melody-strip {
  overflow: visible;
}
.main-stage .melody-area-wrap {
  width: 100%;
  max-height: 100%;
  min-height: 0;
  flex-shrink: 1;
}
.main-stage .guessbar,
.main-stage .revealbar,
.main-stage .labyrinth-info,
.main-stage .labyrinth-player-top {
  flex-shrink: 0;
}
.overlay-layer {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--shell-header-h);
  bottom: 0;
  z-index: 1000;
  pointer-events: none;
  overflow: hidden;
}
.start-panel,
.settings-panel,
.help-panel {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.start-panel:has(#startOverlay:not(.hidden)),
.settings-panel:has(#settingsPanel:not(.hidden)),
.settings-panel:has(#genrePanel:not(.hidden)),
.help-panel:has(#helpBackdrop:not(.hidden)),
.help-panel:has(#helpPanelBackdrop:not(.hidden)) {
  pointer-events: auto;
}
.settings-panel:has(#settingsPanel:not(.hidden)),
.settings-panel:has(#genrePanel:not(.hidden)) {
  background: rgba(0, 0, 0, 0.52);
}
.settings-panel-scroll {
  width: 100%;
  max-width: min(1200px, 100%);
  margin: 0 auto;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 10px 16px 24px;
  box-sizing: border-box;
}

.container{ max-width: 1200px; margin: 0 auto; padding: 20px; }

/* Single play column: use full width inside the shell and keep insets small so tiles stay large */
.board-frame > .main-stage.container {
  max-width: none;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
  padding: 8px 10px 6px;
}

.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  flex-wrap: wrap;
}
h1{ margin:0; font-size: clamp(1.2rem, 2.3vw, 1.8rem); }
.controls{ display:flex; gap:8px; flex-wrap:wrap; }

.btn{
  background: var(--btn-bg); color:var(--text);
  padding:10px 14px; border:none; border-radius:12px; cursor:pointer;
  transition:transform .05s ease, box-shadow .2s ease, background .2s ease, filter .2s ease;
  box-shadow: 0 2px 0 rgba(255,255,255,.06) inset, 0 10px 20px rgba(0,0,0,.35);
}
.btn:hover{ transform: translateY(-1px); }
.btn:active{ transform: translateY(1px); }
.btn.primary{ background: linear-gradient(180deg,#4c7dff,#2458f5); }
.btn.success{ background: linear-gradient(180deg,#3bb273,#2d965f); }
.btn.danger{ background: linear-gradient(180deg,#ff7a6f,#ff3b2f); }

.settings{
  margin: 8px 0 12px; padding: 10px;
  border:1px solid var(--panel-border); border-radius: 12px;
  background: var(--panel-bg);
}
.settings.hidden{ display:none; }
.settings-row{ display:flex; align-items:center; gap: 10px; margin: 4px 0; }
.settings-row label{ min-width: 130px; color: var(--muted); }
.settings-row input[type="number"]{
  width: 110px; padding: 8px 10px; border-radius: 8px; border:1px solid rgba(255,255,255,.1);
  background:#171a2b; color:var(--text);
}
.settings-row input[type="range"]{ flex:1; }
.settings-val{ color: var(--muted); min-width: 3ch; text-align:right; }
.switch{ display:flex; align-items:center; gap:10px; cursor:pointer; }
.switch input{ transform: scale(1.2); }
.debug.hidden{ display:none; }

/* Debug-only elements hidden by default */
.debug-only { display: none; }
/* When Settings panel has .debug-on class, show debug elements */
.settings.debug-on .debug-only { display: flex; }
/* Ensure inline structure for debug block */
.settings.debug-on .debug-only.settings-row { display: flex; }

/* Section titles */
.settings-section-title {
  margin: 12px 0 6px 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.settings-section-title:first-child {
  margin-top: 0;
}

/* Battle Mode section visual separation */
.settings-battle-section {
  margin-top: 6px;
  padding: 10px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
}

.settings-row { display:flex; align-items:center; gap:10px; margin:4px 0; }
.settings-row label{ min-width:180px; }
.settings-row input[type=range]{ flex:1; }
.settings-val{ width:2.5em; text-align:right; font-variant-numeric: tabular-nums; }  


/* Kun debug on pois päältä, tämä luokka piilottaa boksin */
#debugBlock.hidden{
  display: none;
}


/* Melody board */
.melody-strip{
  position: relative;        /* for SVG overlay */
  margin: 4px 0 4px;
  background: rgba(255,255,255,.04);
  border:1px solid rgba(255,255,255,.06);
  border-radius:14px;
  padding: 8px;
  min-height: 100px;
  overflow: hidden;
}

/* Version indicator */
.version-indicator{
  position: absolute;
  bottom: 4px;
  right: 8px;
  font-size: 11px;
  color: rgba(255,255,255,0.5);
  font-family: monospace;
  pointer-events: none;
  user-select: none;
  z-index: 1;
}
.melody-strip svg.connectors{
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.melody-strip svg.guide-overlay{
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

/* Tiles */
.tile{
  width: var(--tile-size);
  height: var(--tile-size);
  background: var(--tile-base); border-radius: 18px; position: relative; cursor:pointer;
  box-shadow: var(--tile-shadow);
  transition: transform .06s ease, filter .2s ease, box-shadow .2s ease;
  border: none; touch-action: none;
}

/* =========================
   SKINS (vain CSS-muuttujia)
   ========================= */

html[data-skin="christmas"]{
  --bg-grad: radial-gradient(1200px 800px at 20% -10%, #0b3d2e 0%, #120b16 62%);
  --panel-bg: rgba(16, 10, 22, .72);
  --panel-border: rgba(255,255,255,.10);
  --btn-bg: #2b2240;
  --tile-base: #2a2f52;
}

html[data-skin="classical"]{
  --bg-grad: radial-gradient(1200px 800px at 20% -10%, #2b2a22 0%, #121216 65%);
  --panel-bg: rgba(18, 18, 22, .72);
  --panel-border: rgba(255,255,255,.10);
  --btn-bg: #2a2a34;
  --tile-base: #2f2f3a;
}

html[data-skin="metal"]{
  --bg-grad: radial-gradient(1200px 800px at 20% -10%, #2a0000 0%, #06070b 65%);
  --panel-bg: rgba(10, 10, 14, .78);
  --panel-border: rgba(255,255,255,.10);
  --btn-bg: #1c1f2e;
  --tile-base: #262a3c;
}

html[data-skin="summer"]{
  --bg-grad: radial-gradient(1200px 800px at 20% -10%, #0b3a66 0%, #061827 65%);
  --panel-bg: rgba(10, 22, 35, .70);
  --panel-border: rgba(255,255,255,.10);
  --btn-bg: #21314a;
  --tile-base: #2a3854;
}

/* Väripesu laatan sisään (var(--tile-color)) */
.tile::before{
  content:"";
  position:absolute; inset:0;
  /* pehmeä värikiilto laatan sisään */
  background:
    radial-gradient(120% 120% at 50% 20%,
      color-mix(in srgb, var(--tile-color) 70%, transparent) 0%,
      transparent 60%);
  /* kevyt sisävarjo, ettei näytä litteältä */
  box-shadow: 0 10px 20px rgba(0,0,0,.25) inset;
}

.tile::after{
  content:"";
  position:absolute; inset: 6px; border-radius: 14px;
  background: var(--tile-color, #999);
  box-shadow: 0 -6px 8px rgba(255,255,255,.15) inset, 0 12px 18px rgba(0,0,0,.35) inset;
}
.tile:active{ transform: translateY(2px); filter: brightness(0.95); }
.tile.active::after{ outline: 2px solid #fff; box-shadow: 0 0 18px rgba(255,255,255,.55), 0 12px 18px rgba(0,0,0,.35) inset; }

/* Laattojen kerrospino: runko < väri < korostus < teksti */
.tile{ position:relative; z-index:0; }
.tile::before{ z-index:1; }         /* väri */
.tile::after{ z-index:2; }          /* aktiivinen valkoinen outline yms. */
.tile .note-label{ z-index:3; }     /* teksti */

/* Loop-alueen korostus */
.tile.loop-selected{
  outline: 3px solid rgba(255, 200, 0, 0.8);
  outline-offset: -2px;
  background-color: rgba(255, 200, 0, 0.15);
}
.tile.loop-selected::before{
  background-color: rgba(255, 200, 0, 0.1);
}

/* Segment Duel: Lukitut segmentit */
.tile.segment-locked {
  opacity: 0.4;
  pointer-events: none;
  filter: grayscale(0.5);
  cursor: not-allowed;
}

/* Segment Duel: Aktiivinen segmentti */
.tile.segment-active {
  outline: 3px solid rgba(255, 200, 0, 0.8);
  outline-offset: -2px;
  background-color: rgba(255, 200, 0, 0.15);
}


/* Note symbols (v2) — keskelle laattaa */
.tile .note-label{
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);

  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  letter-spacing: 0;
  /* Luettavuus kaikilla laattaväreillä (myös keltainen/vaalea): tumma pohja + ääriviiva valkoiselle tekstille */
  font-size: clamp(12px, calc(var(--tile-size) * .32), 22px);
  font-weight: 800;
  line-height: 1;
  padding: .18em .38em;
  border-radius: 7px;
  background: rgba(10, 12, 24, .62);
  color: #fff;
  text-shadow: 0 0 2px #000, 0 1px 2px #000;
  mix-blend-mode: normal;
  pointer-events: none;

  z-index: 1;               /* nosta laattaefektin yläpuolelle */
}
.tile::after { z-index: 0; } /* säilytä jälkeenpäin lisätty nosto */

/* MIDI/Hz overlay (SHIFT+A) */
.tile-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: rgba(0,0,0,0.55);
  border-radius: 14px;
  pointer-events: none;
  text-align: center;
  z-index: 5;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
}
/* Koko skaalautuu laatan mukana (pienet laatat puhelimessa) */
.tile-midi {
  font-size: clamp(9px, calc(var(--tile-size) * 0.26), 15px);
  font-weight: 700;
}
.tile-hz {
  font-size: clamp(8px, calc(var(--tile-size) * 0.2), 12px);
  opacity: 0.9;
  margin-top: 2px;
  white-space: nowrap;
}

/* Korkein/matalin sävel korostus (SHIFT+H) */
.tile-min-pitch {
  outline: 3px solid rgba(100, 180, 255, 0.95);
  outline-offset: -2px;
  box-shadow: 0 0 14px rgba(100, 180, 255, 0.5), inset 0 0 0 1px rgba(255,255,255,0.2);
  z-index: 2;
}
.tile-max-pitch {
  outline: 3px solid rgba(255, 160, 80, 0.95);
  outline-offset: -2px;
  box-shadow: 0 0 14px rgba(255, 160, 80, 0.5), inset 0 0 0 1px rgba(255,255,255,0.2);
  z-index: 2;
}

.guessbar{
  display:flex;
  align-items:center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 0;
  padding-bottom: 2px;
}
.guessbar form{
  display:flex;
  gap: 8px;
  flex:1 1 220px;
  min-width: 0;
}
.guessbar input{
  flex:1; padding: 8px 10px; border-radius: 10px; border:1px solid rgba(255,255,255,.1);
  background:#171a2b; color:var(--text);
}
.score{ color: var(--muted); font-weight:600; }

.revealbar{
  display:flex;
  align-items:center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.revealbar .hidden{ display:none !important; }
.revealbar input{
  flex:1; padding: 8px 10px; border-radius:10px; border:1px solid rgba(255,255,255,.1);
  background:#171a2b; color:var(--text);
}

.labyrinth-info {
  margin-top: 10px;
}

/* Battle Labyrinth: alku- ja loppuruudun välähdys ennen kappaleen alkua */
@keyframes labyrinth-start-end-flash {
  0%, 100% { box-shadow: 0 0 0 0 transparent; outline: 2px solid transparent; }
  50% { box-shadow: 0 0 14px 3px rgba(255, 255, 255, 0.85); outline: 3px solid rgba(255, 255, 255, 0.9); }
}
.tile.labyrinth-start-flash {
  animation: labyrinth-start-end-flash 0.4s ease-in-out 2 forwards;
  outline-offset: 2px;
  z-index: 10;
  position: relative;
}
.tile.labyrinth-end-flash {
  animation: labyrinth-start-end-flash 0.4s ease-in-out 2 forwards;
  outline-offset: 2px;
  animation-delay: 0.08s;
  z-index: 10;
  position: relative;
}

/* Labyrinth: pysyvä loppumerkki (katkoviivakehys + lippu) viimeisen nuotin laatalla */
.tile .labyrinth-end-marker {
  position: absolute;
  inset: 0;
  border-radius: 18px;
  border: 3px dashed rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 10px 2px rgba(255, 255, 255, 0.5);
  pointer-events: none;
  z-index: 4;
}
.tile .labyrinth-end-marker::after {
  content: "🏁";
  position: absolute;
  top: 1px;
  right: 4px;
  font-size: clamp(10px, calc(var(--tile-size) * .28), 22px);
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.7));
}

/* Match 4-option choice box style (font, size, border, radius) */
.labyrinth-title-box {
  display: inline-block;
  padding: 18px 14px;
  min-height: 72px;
  border-radius: 16px;
  font-size: clamp(16px, 1.8vw, 22px);
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
  color: #e9ebf5;
  background: #38a04d;
  border: 2px solid #2b803c;
  box-shadow: 1px 2px 6px rgba(0, 0, 0, 0.4), 0 0 10px rgba(56, 160, 77, 0.4);
  word-break: keep-all;
  overflow-wrap: normal;
  text-wrap: balance;
  box-sizing: border-box;
}

/* Modal (help) */
.hidden{ display:none !important; }
.modal-backdrop{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.55);
  display:flex;
  align-items:center;
  justify-content:center;
  z-index:1000;
}

/* Start screen: scroll tall content on tablets / short viewports (flex center clips overflow) */
.start-overlay.modal-backdrop{
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding:
    max(12px, env(safe-area-inset-top, 0px))
    max(12px, env(safe-area-inset-right, 0px))
    max(12px, env(safe-area-inset-bottom, 0px))
    max(12px, env(safe-area-inset-left, 0px));
}
.start-overlay .intro-modal{
  width: min(100%, 680px);
  max-width: 680px;
  margin-inline: auto;
  flex-shrink: 0;
}

.modal{ max-width:680px; background:rgba(23,26,43,.96); color:#e9edf6; border:1px solid rgba(255,255,255,.08); border-radius:16px; padding:18px 18px 14px; box-shadow:0 20px 60px rgba(0,0,0,.5); }
#helpBackdrop .modal{
  max-height: min(calc(100dvh - 32px), calc(100vh - 32px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal h3{ margin:6px 0 8px; }
.modal p{ color:#cfd6ee; line-height:1.45; }
.modal .modal-actions{ display:flex; justify-content:flex-end; gap:10px; margin-top:10px; }

footer{ margin-top: 18px; color: var(--muted); }

.hidden { display: none !important; }
.choices { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 6px; }
.choices .btn { white-space: nowrap; }

/* === 4-option: yksi rivi, neljä laatikkoa, puskuri, tumma tyyli === */
#choicesBar {
  display: grid !important;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;

  padding: 0 4px;
  margin: 6px auto 0 auto;
  max-width: none;
  width: 100%;

  align-items: stretch;
  justify-items: stretch;
  box-sizing: border-box;
}

/* --- yksittäinen laatikko --- */
#choicesBar .btn {
  width: 100%;
  margin: 0;
  padding: 11px 10px;
  min-height: 52px;
  border-radius: 14px;

  /* typografia */
  font-size: clamp(14px, 1.65vw, 20px);
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
  color: #e9ebf5;

  /* tausta ja kehys */
  background: #24273a;
  border: 2px solid #3d4360;
  box-shadow: 1px 2px 6px rgba(0, 0, 0, 0.4);

  word-break: keep-all;     /* älä katkaise sanoja kesken */
  overflow-wrap: normal;    /* ei väkisin sanan keskeltä poikki */
  text-wrap: balance;

  transition: transform 120ms ease, background-color 120ms ease, border-color 120ms ease;
}

/* hover / focus */
#choicesBar .btn:hover,
#choicesBar .btn:focus {
  background-color: #2f3550;
  border-color: #4e5580;
  transform: scale(1.02);
}

/* === värit valinnan jälkeen === */
#choicesBar .btn.correct {
  background-color: #38a04d !important;   /* kirkas vihreä */
  border-color: #2b803c !important;
  color: #fff !important;
  box-shadow: 0 0 10px rgba(56,160,77,0.7);
  transition: background-color 0.25s ease;
}

#choicesBar .btn.wrong {
  background-color: #c03a3a !important;   /* selkeä punainen */
  border-color: #a53030 !important;
  color: #fff !important;
  box-shadow: 0 0 8px rgba(192,58,58,0.6);
  transition: background-color 0.25s ease;
}

.btn.danger {
  background-color: #b33a3a;
  color: #fff;
  border: 2px solid #a02f2f;
}
.btn.danger:hover {
  background-color: #c94949;
  border-color: #b33a3a;
}

#btnResetScore { padding: 6px 12px; font-weight: 600; }

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-weight: 600;
}

#debugBlock { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
#activeSongInfo { display:inline-flex; align-items:center; gap:4px; font-weight:600; }
#activeSongId { color:#8cf; }
#activeSongTitle { color:#ccc; font-style:italic; }

/* Pidä Reset score -rivin huomautus samalla rivillä napin kanssa */
#btnResetScore {
  flex: 0 0 auto;
}
#btnResetScore + .settings-val {
  white-space: nowrap;
  margin-left: 8px;   /* varmistetaan pieni väli */
  opacity: .8;
}
/* Song ID -rivin tekstin rivitys hallitusti */
#activeSongInfo{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 12px;
  opacity: .9;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: nowrap;            /* ei rivinvaihtoa */
}

#activeSongId{
  opacity: .9;
}

#activeSongTitle{
  opacity: .8;
  white-space: nowrap;            /* pidä samalla rivillä */
  overflow: hidden;               /* jos ei mahdu, katkaise */
  text-overflow: ellipsis;        /* … */
  max-width: clamp(160px, 30vw, 420px);
}

/* Reset score -rivi: pidä huomautus napin vieressä */
#btnResetScore + .settings-val{
  white-space: nowrap;
  margin-left: 8px;
  opacity: .8;
}

#btnFullscreenTop.btn-icon{
  font-size: 18px;
  line-height: 1;
  padding-inline: 10px;
}

/* Nuottien nimet -painike: lihavoitu "C♯" ja selvä päällä/pois-tila (aria-pressed) */
#btnNotesToggle.btn-icon{
  min-width: 44px;
  padding-inline: 8px;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  color: #fff;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.55), 0 10px 20px rgba(0, 0, 0, 0.35);
}
#btnNotesToggle.btn-icon[aria-pressed="true"]{
  background: #ffd23f;
  color: #1a1d2e;
  box-shadow: 0 0 0 2px #ffd23f, 0 0 14px rgba(255, 210, 63, 0.55);
}
/* Hz-taajuudet päällä (tuplaklikkaus / Shift+A): painikkeessa "Hz", syaani */
#btnNotesToggle.btn-icon.hz-on{
  background: #3ad1ff;
  color: #0d1b2a;
  box-shadow: 0 0 0 2px #3ad1ff, 0 0 14px rgba(58, 209, 255, 0.55);
}

/* Compact settings rows: pitää elementit yhdellä rivillä */
.settings-row.compact {
  flex-wrap: nowrap;
  gap: 14px;
}

/* Liukusäätimille maltillisempi leveys */
.settings-row input[type=range] {
  flex: 0 1 320px;      /* aiemmin flex:1 -> rajoitetaan leveys */
  max-width: 320px;
}
#optTempoVal {
  min-width: 3em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
/*                            ILKAN LISÄYS *** */
#optVolumeVal {
  min-width: 3em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Varmistus: Volume ja Transpose -etiketit näkyvät */
.settings-row label[for="optVolume"],
.settings-row label[for="optTranspose"] {
  min-width: 160px;
}

/* Korjaa vielä että "settings-val" ei puske alas */
.settings-row .settings-val {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* Kaksi saraketta: vasen ja oikea lohko; rivit tasa-aligned */
.settings-grid{
  display: grid;
  grid-template-columns: minmax(340px, 1fr) minmax(340px, 1fr);
  gap: 12px 28px;              /* rivi- ja sarakeväli */
  align-items: center;
  margin: 6px 0 10px;
}

/* Yhden kontrollin sisäinen 3-sarakkeen ruudukko:
   [label 160px] [slider täyttää] [arvo 3ch] */
.settings-grid .control{
  display: grid;
  grid-template-columns: 160px 1fr 3.5ch;
  column-gap: 12px;
  align-items: center;
}

/* Slidereille täysi leveys oman solun sisällä */
.settings-grid .control input[type=range]{ width: 100%; }

/* Arvokenttä oikealle, numeroina tasavälit */
.settings-grid .control .settings-val{
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Responsiivisuus: kapeilla näytöillä pinotaan sarakkeet */
@media (max-width: 1024px){
  .settings-grid{
    grid-template-columns: 1fr;   /* yksi sarake */
  }
}

.btn-group{ display:inline-flex; align-items:center; gap:6px; margin:0 8px; }
.btn-group.compact{ gap:4px; margin:0 4px; }
.btn.small{ padding:4px 8px; font-size:0.95rem; border-radius:10px; }
.btn.icon-small{
  display:inline-flex; align-items:center; justify-content:center;
  width:28px; height:28px; border-radius:8px; font-size:16px;
  padding:0; min-width:28px;
  box-shadow: 0 2px 0 rgba(255,255,255,.06) inset, 0 8px 16px rgba(0,0,0,.3);
}
.badge{
  display:inline-block; min-width:2.5ch; text-align:center;
  padding:2px 6px; border-radius:10px;
  background:rgba(255,255,255,0.08); color:#e6ecff; font-variant-numeric:tabular-nums;
}
.badge-compact{
  min-width:2ch; padding:1px 4px; font-size:0.85rem;
}

.btn.icon{
  display:inline-flex; align-items:center; justify-content:center;
  width:36px; height:36px; border-radius:10px; font-size:18px;
  line-height:1; padding:0;
}
.btn.icon[aria-pressed="true"]{
  outline:2px solid rgba(255,255,255,.3);
  background:rgba(255,255,255,.08);
}
/* Vihreä Play-nappi */
.btn.play{
  background: #22c55e;          /* Tailwindin green-500 tyyppinen */
  color: #0b1a10;
  box-shadow: 0 6px 16px rgba(34,197,94,.25);
}
.btn.play:hover{ filter: brightness(1.06); }
.btn.play:active{ transform: translateY(1px); }

/* --- Vihreä Play-nappi (3D + hover) --- */
.btn.play {
  background: linear-gradient(180deg, #22c55e 0%, #16a34a 100%); /* vihreä liukuväri */
  color: #e9fcef;
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow:
    0 4px 12px rgba(0,0,0,0.35),          /* yleinen syvyys */
    inset 0 1px 0 rgba(255,255,255,0.15), /* kevyt hehku yläreunassa */
    inset 0 -2px 6px rgba(0,0,0,0.25);    /* 3D-syvyys */
  border-radius: 10px;
  font-weight: 600;
  transition: all 0.15s ease-in-out;
}

/* Hover kirkastaa ja nostaa hieman */
.btn.play:hover {
  background: linear-gradient(180deg, #26d366 0%, #18b14f 100%);
  box-shadow:
    0 6px 14px rgba(34,197,94,0.45),
    inset 0 1px 0 rgba(255,255,255,0.25),
    inset 0 -2px 6px rgba(0,0,0,0.25);
  transform: translateY(-1px);
}

/* Painettaessa laskeutuu kevyesti */
.btn.play:active {
  transform: translateY(1px);
  filter: brightness(0.95);
}

/* Väripaletin flash (C-näppäin) */
#paletteFlash {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-size: 14px;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
#paletteFlash.show {
  opacity: 1;
}

.intro-modal h2{
  margin-top: 4px;
  margin-bottom: 8px;
}
.intro-modal p{
  margin-bottom: 8px;
  color: #cfd6ee;
  line-height: 1.45;
}
.intro-mode-row{
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 8px;
}
.intro-h2h h3{
  margin: 0 0 8px 0;
  font-size: 1.05rem;
}
.intro-h2h-fields{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 14px;
  margin-bottom: 6px;
}
.intro-h2h .field{
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
}
.intro-h2h .intro-h2h-fields .field{
  margin-bottom: 0;
}
.intro-h2h input{
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(10, 15, 35, 0.9);
  color: #e9edf6;
}
.intro-h2h input:focus{
  outline: 1px solid rgba(255,255,255,0.35);
}
.intro-actions{
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
  flex-wrap: wrap;
}

/* Start screen background */
/* startOverlay käyttää .modal-backdrop position:fixed -tyyliä */
.start-background{
  position: absolute;
  inset: 0;
  background: radial-gradient(1200px 800px at 20% -10%, #1f2350 0%, #0f1120 60%);
  filter: blur(8px) opacity(0.4);
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
}

/* Mock-pelilauta taustaan - CSS-grid värikkäistä laatoista */
.start-background::before{
  content: "";
  position: absolute;
  inset: 0;
  background-image: 
    /* Rivi 1 */
    radial-gradient(circle at 8% 12%, rgba(255,0,0,0.4) 25px, transparent 25px),
    radial-gradient(circle at 18% 12%, rgba(255,255,0,0.4) 25px, transparent 25px),
    radial-gradient(circle at 28% 12%, rgba(0,128,0,0.4) 25px, transparent 25px),
    radial-gradient(circle at 38% 12%, rgba(0,178,238,0.4) 25px, transparent 25px),
    radial-gradient(circle at 48% 12%, rgba(255,0,0,0.4) 25px, transparent 25px),
    radial-gradient(circle at 58% 12%, rgba(255,140,0,0.4) 25px, transparent 25px),
    radial-gradient(circle at 68% 12%, rgba(255,255,0,0.4) 25px, transparent 25px),
    radial-gradient(circle at 78% 12%, rgba(0,178,238,0.4) 25px, transparent 25px),
    radial-gradient(circle at 88% 12%, rgba(128,0,128,0.4) 25px, transparent 25px),
    radial-gradient(circle at 98% 12%, rgba(0,128,0,0.4) 25px, transparent 25px),
    /* Rivi 2 */
    radial-gradient(circle at 8% 25%, rgba(0,178,238,0.35) 25px, transparent 25px),
    radial-gradient(circle at 18% 25%, rgba(255,140,0,0.35) 25px, transparent 25px),
    radial-gradient(circle at 28% 25%, rgba(255,0,0,0.35) 25px, transparent 25px),
    radial-gradient(circle at 38% 25%, rgba(255,255,0,0.35) 25px, transparent 25px),
    radial-gradient(circle at 48% 25%, rgba(0,128,0,0.35) 25px, transparent 25px),
    radial-gradient(circle at 58% 25%, rgba(128,0,128,0.35) 25px, transparent 25px),
    radial-gradient(circle at 68% 25%, rgba(255,0,0,0.35) 25px, transparent 25px),
    radial-gradient(circle at 78% 25%, rgba(255,255,0,0.35) 25px, transparent 25px),
    radial-gradient(circle at 88% 25%, rgba(0,178,238,0.35) 25px, transparent 25px),
    radial-gradient(circle at 98% 25%, rgba(255,140,0,0.35) 25px, transparent 25px),
    /* Rivi 3 */
    radial-gradient(circle at 8% 38%, rgba(255,255,0,0.3) 25px, transparent 25px),
    radial-gradient(circle at 18% 38%, rgba(0,128,0,0.3) 25px, transparent 25px),
    radial-gradient(circle at 28% 38%, rgba(255,140,0,0.3) 25px, transparent 25px),
    radial-gradient(circle at 38% 38%, rgba(128,0,128,0.3) 25px, transparent 25px),
    radial-gradient(circle at 48% 38%, rgba(0,178,238,0.3) 25px, transparent 25px),
    radial-gradient(circle at 58% 38%, rgba(255,0,0,0.3) 25px, transparent 25px),
    radial-gradient(circle at 68% 38%, rgba(0,128,0,0.3) 25px, transparent 25px),
    radial-gradient(circle at 78% 38%, rgba(255,255,0,0.3) 25px, transparent 25px),
    radial-gradient(circle at 88% 38%, rgba(255,140,0,0.3) 25px, transparent 25px),
    radial-gradient(circle at 98% 38%, rgba(0,178,238,0.3) 25px, transparent 25px),
    /* Rivi 4 */
    radial-gradient(circle at 8% 51%, rgba(0,178,238,0.25) 25px, transparent 25px),
    radial-gradient(circle at 18% 51%, rgba(255,0,0,0.25) 25px, transparent 25px),
    radial-gradient(circle at 28% 51%, rgba(128,0,128,0.25) 25px, transparent 25px),
    radial-gradient(circle at 38% 51%, rgba(255,255,0,0.25) 25px, transparent 25px),
    radial-gradient(circle at 48% 51%, rgba(255,140,0,0.25) 25px, transparent 25px),
    radial-gradient(circle at 58% 51%, rgba(0,128,0,0.25) 25px, transparent 25px),
    radial-gradient(circle at 68% 51%, rgba(255,0,0,0.25) 25px, transparent 25px),
    radial-gradient(circle at 78% 51%, rgba(0,178,238,0.25) 25px, transparent 25px),
    radial-gradient(circle at 88% 51%, rgba(255,255,0,0.25) 25px, transparent 25px),
    radial-gradient(circle at 98% 51%, rgba(128,0,128,0.25) 25px, transparent 25px),
    /* Rivi 5 */
    radial-gradient(circle at 8% 64%, rgba(255,140,0,0.2) 25px, transparent 25px),
    radial-gradient(circle at 18% 64%, rgba(0,128,0,0.2) 25px, transparent 25px),
    radial-gradient(circle at 28% 64%, rgba(255,255,0,0.2) 25px, transparent 25px),
    radial-gradient(circle at 38% 64%, rgba(255,0,0,0.2) 25px, transparent 25px),
    radial-gradient(circle at 48% 64%, rgba(128,0,128,0.2) 25px, transparent 25px),
    radial-gradient(circle at 58% 64%, rgba(0,178,238,0.2) 25px, transparent 25px),
    radial-gradient(circle at 68% 64%, rgba(255,140,0,0.2) 25px, transparent 25px),
    radial-gradient(circle at 78% 64%, rgba(0,128,0,0.2) 25px, transparent 25px),
    radial-gradient(circle at 88% 64%, rgba(255,255,0,0.2) 25px, transparent 25px),
    radial-gradient(circle at 98% 64%, rgba(255,0,0,0.2) 25px, transparent 25px),
    /* Rivi 6 */
    radial-gradient(circle at 8% 77%, rgba(128,0,128,0.15) 25px, transparent 25px),
    radial-gradient(circle at 18% 77%, rgba(0,178,238,0.15) 25px, transparent 25px),
    radial-gradient(circle at 28% 77%, rgba(255,0,0,0.15) 25px, transparent 25px),
    radial-gradient(circle at 38% 77%, rgba(255,140,0,0.15) 25px, transparent 25px),
    radial-gradient(circle at 48% 77%, rgba(255,255,0,0.15) 25px, transparent 25px),
    radial-gradient(circle at 58% 77%, rgba(0,128,0,0.15) 25px, transparent 25px),
    radial-gradient(circle at 68% 77%, rgba(128,0,128,0.15) 25px, transparent 25px),
    radial-gradient(circle at 78% 77%, rgba(255,0,0,0.15) 25px, transparent 25px),
    radial-gradient(circle at 88% 77%, rgba(0,178,238,0.15) 25px, transparent 25px),
    radial-gradient(circle at 98% 77%, rgba(255,255,0,0.15) 25px, transparent 25px);
  background-size: 100% 100%;
  opacity: 0.6;
}

/* Start hero: title (left) | Play (center) | Help (right) */
.start-hero{
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px 12px;
  margin-bottom: 10px;
}
.start-hero .start-title{
  margin: 0;
  text-align: left;
  font-size: clamp(1.05rem, 2.4vw, 1.85rem);
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
}
.start-hero-center{
  justify-self: center;
}
.start-hero-end{
  justify-self: end;
}
.btn-start-primary{
  box-shadow:
    0 6px 18px rgba(34, 197, 94, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    inset 0 -2px 6px rgba(0, 0, 0, 0.25);
}
.btn-start-help{
  white-space: nowrap;
  opacity: 0.92;
  font-weight: 500;
  background: rgba(36, 40, 66, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

@media (max-width: 720px) {
  .start-hero {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-bottom: 8px;
  }
  .start-hero .start-title {
    flex: 1 1 100%;
    text-align: center;
  }
  .start-hero-center,
  .start-hero-end {
    flex: 0 0 auto;
  }
}

/* Large start button */
.btn-large{
  padding: 14px 28px;
  font-size: 1.25rem;
  font-weight: 600;
}

.start-hide-intro-label{
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.start-genres-tight{
  margin-bottom: 8px;
}
.battle-mode-selector{
  margin: 10px 0;
}
.battle-mode-selector > label{
  display: block;
  margin-top: 6px;
}
.battle-mode-selector > label + label{
  margin-top: 4px;
}
.start-segment-control{
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Start step boxes */
.start-step{
  background: rgba(23, 26, 43, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 12px;
  margin: 10px 0;
}
.start-step h3{
  margin: 0 0 8px 0;
  font-size: 1.05rem;
  color: var(--text);
}

/* Help button (bottom-left) */
.btn-help{
  position: fixed;
  bottom: 16px;
  left: 16px;
  z-index: 999;
  padding: 8px 14px;
  font-size: 0.9rem;
  background: rgba(23, 26, 43, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text);
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s ease, transform 0.1s ease;
}
.btn-help:hover{
  background: rgba(23, 26, 43, 0.95);
  transform: translateY(-1px);
}
.btn-help:active{
  transform: translateY(0);
}

/* Help modal */
.help-modal{
  max-width: 900px;
  max-height: min(90dvh, 90vh, calc(100dvh - var(--shell-header-h, 92px) - 24px), calc(100vh - var(--shell-header-h, 92px) - 24px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Help shortcuts */
.help-shortcuts{
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 16px 0;
  justify-content: center;
}
.btn-shortcut{
  min-width: 60px;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: var(--text);
  font-family: monospace;
  font-weight: 600;
  cursor: default;
  user-select: none;
}

/* Help panel content (upotettu alkunäyttöön) */
.help-panel-content{
  margin-top: 8px;
}
.help-panel-content ul{
  margin: 8px 0;
  padding-left: 24px;
  color: #cfd6ee;
  line-height: 1.5;
}
.help-panel-content li{
  margin: 4px 0;
}

/* Kaksi-palstainen layout */
.help-columns{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
.help-column{
  display: flex;
  flex-direction: column;
}

.help-panel-content h4{
  font-size: 0.95rem;
  font-weight: 600;
  margin-top: 12px;
  margin-bottom: 6px;
  color: var(--text);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 3px;
}
.help-column h4:first-child{
  margin-top: 0;
}

/* Help shortcut sections */
.help-shortcut-section{
  margin: 6px 0 12px 0;
}
.help-shortcut-row{
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 3px 0;
  padding: 3px 0;
}
.help-key{
  min-width: 90px;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  color: var(--text);
  font-family: monospace;
  font-weight: 600;
  font-size: 0.85rem;
  text-align: center;
  flex-shrink: 0;
}
.help-desc{
  color: #cfd6ee;
  line-height: 1.3;
  font-size: 0.9rem;
  flex: 1;
}

/* Responsiivisuus: yksi palsta pienemmillä näytöillä */
@media (max-width: 900px) {
  .help-columns{
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

.melody-area-wrap{
  position: relative;
}
.labyrinth-player-top {
  margin-top: 10px;
  margin-bottom: 10px;
  padding: 12px 20px;
  font-size: 1.35rem;
  font-weight: 700;
  color: #e9ecff;
  border-radius: 10px;
  display: inline-block;
  letter-spacing: 0.02em;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  transition: background 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease;
}
.labyrinth-player-top.labyrinth-player-p1 {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.45), rgba(30, 58, 138, 0.55));
  border: 2px solid rgba(96, 165, 250, 0.65);
  box-shadow: 0 4px 20px rgba(59, 130, 246, 0.25);
}
.labyrinth-player-top.labyrinth-player-p2 {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.4), rgba(22, 163, 74, 0.55));
  border: 2px solid rgba(74, 222, 128, 0.65);
  box-shadow: 0 4px 20px rgba(34, 197, 94, 0.25);
}
.labyrinth-player-top .labyrinth-player-name {
  font-size: 1.5rem;
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.25);
}

/* Tulosnäyttö: parempi / heikompi suoritus (pisteet tai labyrintissa aika / väärät) */
.battle-summary-score-higher {
  color: #86efac;
  font-weight: 700;
}
.battle-summary-score-lower {
  color: #fca5a5;
  font-weight: 600;
}

.start-step2-battle .battle-row {
  margin-bottom: 8px;
}
.start-step2-battle .start-battle-check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 6px 0;
  font-size: 0.95rem;
  line-height: 1.35;
}
.start-step2-battle .start-battle-check input {
  margin-top: 3px;
}
.start-step2-battle .start-overlay-segment-row .control {
  margin-top: 8px;
}

.labyrinth-song-order {
  margin-top: 6px;
  font-size: 1.05rem;
  font-weight: 600;
  color: #93c5fd;
  display: block;
}
.labyrinth-status-bottom{
  margin-top: 8px;
  font-size: 1rem;
  color: #c7d2fe;
  font-weight: 500;
}
.labyrinth-regenerate{
  margin-left: auto;
  padding: 8px 16px;
  font-size: 0.9rem;
  background: #3b82f6;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
  display: inline-block;
}
.labyrinth-regenerate.hidden{
  display: none !important;
}
.labyrinth-regenerate:hover{
  background: #2563eb;
}
.labyrinth-status-bottom .labyrinth-errors{
  font-size: 11px;
  opacity: 0.7;
  margin-left: 12px;
}

.labyrinth-battle-stats {
  font-size: 1.4rem;
  font-weight: 700;
  color: #e9ebf5;
}
.labyrinth-battle-stats.hidden {
  display: none !important;
}

.battle-hud{
  margin-top: 4px;
  font-size: 14px;
  color: #cfd6ee;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: baseline;
}
.battle-hud span{
  white-space: nowrap;
}

.battle-time-wrap{
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.battle-clock{
  position: relative;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid #cfd6ee;
  background: rgba(23, 26, 43, 0.6);
}
.battle-clock-hand{
  position: absolute;
  left: 50%;
  bottom: 50%;
  width: 2px;
  height: 45%;
  margin-left: -1px;
  background: #cfd6ee;
  transform-origin: 50% 100%;
  border-radius: 1px;
}

/* Battle summary modal */
.battle-summary-modal{
  max-width: 840px;
}

.battle-summary-subtitle{
  margin: 4px 0 12px;
  font-size: 13px;
  color: #b9c2e6;
}

.battle-summary-table-wrapper{
  max-height: 320px;
  overflow: auto;
  margin-bottom: 10px;
}

.battle-summary-table{
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.battle-summary-table thead{
  background: rgba(255,255,255,0.04);
}

.battle-summary-table th,
.battle-summary-table td{
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
}

.battle-summary-table th{
  font-weight: 600;
  color: #e9edf6;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.battle-summary-table tbody tr:nth-child(odd){
  background: rgba(255,255,255,0.02);
}

.battle-summary-table tbody tr:nth-child(even){
  background: rgba(255,255,255,0.04);
}

.battle-summary-table tbody tr:first-child{
  border-top: 1px solid rgba(255,255,255,0.04);
}

.battle-summary-table tbody tr td:nth-child(2){
  font-weight: 600; /* Yhteispisteet korostetusti */
}

.battle-summary-winner{
  margin-top: 6px;
  margin-bottom: 4px;
  font-weight: 600;
  color: #ffdf6b;
}
.btn.btn-secondary{
  background: #3a425f;
}

.battle-summary-table th,
.battle-summary-table td {
  padding: 12px 18px;
  font-size: 17px;
}

.battle-summary-table th {
  background: linear-gradient(90deg, #5a78ff50, #ff8c0050);
  font-size: 16px;
}

.battle-summary-table .score-total {
  font-weight: 700;
  color: #ffdf6b;
  font-size: 19px;
}

/* ---- Battle-tulos: isompi ja luettavampi ---- */

.battle-summary-modal{
  max-width: 880px;
  width: min(92vw, 880px);
  margin: 0 auto;
  background: radial-gradient(circle at top left,
    #262c4c 0, #15192b 45%, #0b1021 100%);
  border-radius: 20px;
  padding: 24px 30px 20px;
  box-shadow: 0 28px 70px rgba(0,0,0,0.85);
  border: 1px solid rgba(255,255,255,0.08);
  color: #e8ecff;
}

.battle-summary-modal h2{
  margin: 0 0 4px;
  font-size: 24px;
}

.battle-summary-subtitle{
  margin: 0 0 18px;
  font-size: 14px;
  color: #c1c7e6;
}

/* Taulukko isommaksi */

.battle-summary-table{
  width: 100%;
  border-collapse: collapse;
  font-size: 16px;
  margin-bottom: 14px;
}

.battle-summary-table thead{
  background: linear-gradient(90deg,
    rgba(90,120,255,0.45),
    rgba(255,140,0,0.45));
}

.battle-summary-table th,
.battle-summary-table td{
  padding: 12px 16px;
  text-align: left;
  white-space: nowrap;
}

.battle-summary-table th{
  font-weight: 600;
  font-size: 15px;
  color: #f7f8ff;
  border-bottom: 1px solid rgba(255,255,255,0.35);
}

.battle-summary-table tbody tr:nth-child(odd){
  background: rgba(255,255,255,0.03);
}

.battle-summary-table tbody tr:nth-child(even){
  background: rgba(255,255,255,0.08);
}

.battle-summary-table td.player{
  font-weight: 600;
}

.battle-summary-table td.score-total{
  font-weight: 700;
  font-size: 18px;
  color: #ffdf6b;
}

/* Voittajan rivi (Audio Labyrinth) */
.battle-summary-table tbody tr.battle-summary-winner-row {
  background: linear-gradient(90deg, rgba(56, 160, 77, 0.35), rgba(56, 160, 77, 0.15)) !important;
  border-left: 4px solid #38a04d;
  font-weight: 700;
  color: #e9ebf5;
}
.battle-summary-table tbody tr.battle-summary-winner-row td {
  font-weight: 700;
}

/* Voittajarivi ja napit */

.battle-summary-winner{
  margin-top: 4px;
  margin-bottom: 14px;
  font-size: 17px;
  font-weight: 700;
  color: #ffdf6b;
}

.battle-summary-buttons{
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.battle-summary-buttons .btn{
  font-size: 14px;
  padding: 8px 20px;
  border-radius: 999px;
}

.battle-summary-default.hidden,
.battle-summary-labyrinth.hidden {
  display: none !important;
}

.battle-summary-labyrinth-title {
  margin: 0 0 12px;
  font-size: 1.15rem;
  font-weight: 700;
  color: #e8ecff;
}

.battle-summary-labyrinth-sep {
  height: 1px;
  background: rgba(255,255,255,0.2);
  margin: 14px 0;
}

.battle-summary-toggle-btn {
  margin-top: 10px;
}

.battle-summary-detail-player-header {
  text-align: center;
}

.settings-row-mode .settings-val{
  display: flex;
  justify-content: flex-start;   /* tai flex-end jos haluat oikealle */
  margin-top: 4px;
}

.settings-row-mode #btnModeSelector{
  margin-top: 4px;
}

.start-modes {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.start-genres {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255,255,255,.2);
}

.start-genres .small {
  font-size: 0.9rem;
  opacity: 0.9;
  margin-bottom: 0.5rem;
}

/* Kelluva debug-boksi oikeaan yläkulmaan */
.debug-box {
  position: fixed;
  top: 12px;
  right: 12px;
  min-width: 260px;
  background: rgba(5, 8, 20, 0.9);
  border-radius: 10px;
  padding: 10px 14px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.6);
  font-size: 13px;
  line-height: 1.4;
  z-index: 500; /* .top-chrome on 200 ja .overlay-layer 1000: debug näkyy työkalupalkin päällä */
}
.debug-box-drag {
  cursor: grab;
  user-select: none;
  touch-action: none;
  margin: -4px -6px 8px -6px;
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.debug-box-drag:active {
  cursor: grabbing;
}
.debug-box.hidden {
  display: none;
}

.debug-box .dbg-label {
  font-weight: 600;
  color: #8fb4ff;
  margin-right: 6px;
}
.debug-box strong {
  color: #9cf;
}

/* === Floating debug box (päänäytön yläoikea kulma) === */

#debugSongBox {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 1300;

  min-width: 260px;
  max-width: 360px;
  padding: 8px 12px;

  background: rgba(5, 8, 25, 0.96);
  border-radius: 10px;
  box-shadow: 0 18px 40px rgba(0,0,0,.55);

  font-size: 13px;
  line-height: 1.3;
  color: #e5ecff;
}

/* Debug: Current song label (Load by ID -napin perässä) */
#activeSongDebug{
  display: inline-flex;
  align-items: center;
  margin-left: 12px;
  opacity: .9;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: clamp(160px, 30vw, 520px);
}


/* piilotusluokka – JS lisää/poistaa tämän */
#debugSongBox.hidden {
  display: none;
}

/* pikkustailia otsikoille */
#debugSongBox .dbg-label {
  display: block;
  font-weight: 600;
  color: #8fc5ff;
}
#debugSongBox .dbg-value {
  display: inline;
}
/* =========================
   CHRISTMAS: Garland frame
   ========================= */
html[data-skin="christmas"] .container{
  --frame: clamp(18px, 3.2vw, 48px);

  border: var(--frame) solid transparent;
  border-image-source: url("/static/skins/christmas/garland-frame.png");
  border-image-slice: 160;
  border-image-repeat: round;

  padding: calc(6px + var(--frame));
  margin: 0 auto;

  box-shadow: 0 0 60px rgba(255,180,180,.20), inset 0 0 35px rgba(0,0,0,.35);
}

html[data-skin="classical"] .container{
  --frame: clamp(18px, 3.2vw, 48px);

  border: var(--frame) solid transparent;
  border-image-source: url("/static/skins/classical/Classical_1330.png");
  border-image-slice: 160;
  border-image-repeat: round;

  padding: calc(6px + var(--frame));

  margin: 0 auto;
}

html[data-skin="metal"] .container{
  --frame: clamp(18px, 3.2vw, 48px);

  border: var(--frame) solid transparent;
  border-image-source: url("/static/skins/classicrock/ClassicRock.png");
  border-image-slice: 160;
  border-image-repeat: round;

  padding: calc(6px + var(--frame));

  margin: 0 auto;
}

html[data-skin="summer"] .container{
  --frame: clamp(18px, 3.2vw, 48px);

  border: var(--frame) solid transparent;
  border-image-source: url("/static/skins/summer/Summer.png");
  border-image-slice: 160;
  border-image-repeat: round;

  padding: calc(6px + var(--frame));

  margin: 0 auto;
}

/* Ornamental skins: frame inset must win over generic main-stage padding */
html[data-skin="christmas"] .board-frame > .main-stage.container,
html[data-skin="classical"] .board-frame > .main-stage.container,
html[data-skin="metal"] .board-frame > .main-stage.container,
html[data-skin="summer"] .board-frame > .main-stage.container {
  padding: calc(5px + var(--frame)) calc(6px + var(--frame)) calc(4px + var(--frame));
}

/* Piilota käyttämättömät rivit (vapauttaa tilaa, ornamentti ylemmäs) */
.revealbar{ display:none !important; }
footer{ display:none !important; }

/* =========================
   Responsive: tablet (1024) + tighter phone (768)
   ========================= */
@media (max-width: 1024px) {
  .app-shell {
    --shell-header-h: 118px;
  }
  .top-chrome-inner {
    padding: 16px 16px 10px;
  }
  .container {
    padding: 16px;
  }
  html[data-skin="christmas"] .container,
  html[data-skin="classical"] .container,
  html[data-skin="metal"] .container,
  html[data-skin="summer"] .container {
    padding: calc(6px + var(--frame));
  }

  h1 {
    font-size: clamp(1.05rem, 2.1vw, 1.65rem);
  }
  .topbar {
    gap: 8px;
  }
  .controls {
    gap: 6px;
  }
  .btn {
    padding: 8px 12px;
  }
  .btn.icon-small {
    width: 26px;
    height: 26px;
    min-width: 26px;
    font-size: 15px;
  }

  .melody-strip {
    min-height: 84px;
    margin: 4px 0 4px;
    padding: 8px;
  }

  .guessbar {
    gap: 10px;
    align-items: flex-start;
  }
  .guessbar input {
    padding: 8px 10px;
  }
  .revealbar input {
    padding: 7px 9px;
  }

  .settings {
    margin: 8px 0 12px;
    padding: 10px;
  }
  .settings-section-title {
    margin: 12px 0 6px;
    font-size: 0.95rem;
  }
  .settings-section-title:first-child {
    margin-top: 0;
  }
  .settings-battle-section {
    padding: 10px;
    margin-top: 6px;
  }
  .settings-row {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px;
    margin: 5px 0;
  }
  .settings-row label {
    min-width: min(160px, 100%);
  }

  .start-hero .start-title {
    font-size: clamp(1.05rem, 3.8vw, 1.65rem);
  }
  .start-step {
    padding: 12px;
    margin: 10px 0;
  }
  .start-step h3 {
    margin-bottom: 8px;
    font-size: 1rem;
  }
  .btn-large {
    padding: 12px 22px;
    font-size: 1.15rem;
  }
  .intro-mode-row {
    gap: 8px;
    margin: 4px 0 8px;
  }
  .battle-mode-selector {
    margin: 10px 0;
  }

  /* Skins: allow topbar / controls to wrap on tablets */
  html[data-skin="christmas"] .topbar,
  html[data-ornament="1"] .topbar {
    flex-wrap: wrap;
  }
  html[data-skin="christmas"] .topbar h1,
  html[data-ornament="1"] .topbar h1 {
    white-space: normal;
  }
  html[data-skin="christmas"] .controls,
  html[data-ornament="1"] .controls {
    flex-wrap: wrap;
  }
}

@media (max-width: 768px) {
  .app-shell {
    --shell-header-h: 132px;
  }
  .top-chrome-inner {
    padding: 12px 12px 8px;
  }
  .container {
    padding: 12px;
  }
  html[data-skin="christmas"] .container,
  html[data-skin="classical"] .container,
  html[data-skin="metal"] .container,
  html[data-skin="summer"] .container {
    padding: calc(6px + var(--frame));
  }

  .topbar {
    gap: 6px;
  }
  .controls {
    gap: 5px;
  }
  .btn {
    padding: 7px 10px;
    border-radius: 10px;
  }

  .melody-strip {
    min-height: 72px;
    margin: 4px 0 3px;
    padding: 7px;
  }
  .guessbar {
    gap: 8px;
  }
  .guessbar form {
    flex: 1 1 100%;
  }

  .settings {
    padding: 8px;
    margin: 6px 0 10px;
  }
  .settings-battle-section {
    padding: 8px;
  }
  .settings-row label {
    min-width: 100%;
  }

  .start-overlay.modal-backdrop {
    padding:
      max(8px, env(safe-area-inset-top, 0px))
      max(10px, env(safe-area-inset-right, 0px))
      max(10px, env(safe-area-inset-bottom, 0px))
      max(10px, env(safe-area-inset-left, 0px));
  }
  .start-overlay .intro-modal {
    padding: 14px 14px 12px;
    border-radius: 14px;
  }
  .start-hero .start-title {
    font-size: clamp(1rem, 5vw, 1.5rem);
  }
  .start-step {
    padding: 10px;
    margin: 8px 0;
  }
  .btn-large {
    padding: 10px 18px;
    font-size: 1.05rem;
  }

  .intro-h2h-fields {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}

/* =========================
   CHRISTMAS: topbar no-wrap
   ========================= */
html[data-skin="christmas"] .topbar{
  flex-wrap: nowrap;
}

html[data-skin="christmas"] .topbar h1{
  white-space: nowrap;          /* "MUBIK – Guess the Melody" ei rivity */
  font-size: clamp(1.05rem, 2.0vw, 1.6rem); /* aavistus pienempi */
}

html[data-skin="christmas"] .controls{
  flex-wrap: nowrap;            /* Genres ei putoa seuraavalle riville */
  gap: 6px;                     /* vähän tiiviimpi */
}

html[data-skin="christmas"] .controls .btn{
  padding: 9px 12px;            /* aavistus kapeammaksi */
}

html[data-ornament="1"] .topbar{ flex-wrap: nowrap; }
html[data-ornament="1"] .topbar h1{
  white-space: nowrap;
  font-size: clamp(1.05rem, 2.0vw, 1.6rem);
}
html[data-ornament="1"] .controls{ flex-wrap: nowrap; gap: 6px; }
html[data-ornament="1"] .controls .btn{ padding: 9px 12px; }

/* Tablet Mode */
.tablet-mode {
  /* Global tablet mode hook */
}

/* Floating Mini Keyboard */
.mini-keyboard {
  position: fixed;
  background: rgba(23, 26, 43, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 8px;
  z-index: 10001; /* Above overlays */
  touch-action: none;
  user-select: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  min-width: 180px;
}

.mini-keyboard.hidden {
  display: none;
}

.mini-keyboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  margin-bottom: 8px;
  cursor: move;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.mini-keyboard-close {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
}

.mini-keyboard-close:hover {
  background: rgba(255, 255, 255, 0.1);
}

.mini-keyboard-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}

.mini-keyboard-grid:last-child {
  margin-bottom: 0;
}

.mini-key {
  min-width: 48px;
  min-height: 48px;
  padding: 12px 8px;
  background: rgba(36, 40, 66, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  transition: transform 0.1s, background 0.2s;
  user-select: none;
}

.mini-key:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.15);
}

.mini-key-active {
  background: rgba(76, 125, 255, 0.4);
  border-color: rgba(76, 125, 255, 0.6);
}

.mini-key-alt-active {
  background: rgba(255, 200, 0, 0.4);
  border-color: rgba(255, 200, 0, 0.6);
}

.mini-key-zero {
  grid-column: 2;
}

.mini-key-zero-wide {
  grid-column: span 2;
}

.mini-key-alt-wide {
  grid-column: span 4;
}

.mini-key-shift-active {
  background: rgba(76, 200, 255, 0.4);
  border-color: rgba(76, 200, 255, 0.6);
}

.mini-key-modifier {
  /* Styling for modifier keys like Alt */
}

/* Admin page must scroll normally */
body:has(.admin-wrap) {
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 100vh;
}

html:has(body .admin-wrap) {
  overflow-y: auto;
  height: auto;
}

body:has(.admin-wrap) .admin-wrap {
  padding: 0 16px 48px;
}

/* =========================
   Laiteprofiilit (static/js/device-profile.js)
   html[data-device="phone|tablet|desktop"], html[data-orient="portrait|landscape"], html[data-compact="1"]
   ========================= */

/* Turva-alueet: lovi, pyöristetyt kulmat, kotipalkki (viewport-fit=cover).
   Korkeus = todellinen näkyvä alue (--app-h, device-profile.js). Aiempi min-height: 100vh
   ohitti max-heightin ja venytti kuoren iOS Safarissa työkalupalkin alle → vastausnapit piiloon. */
.app-shell {
  height: 100dvh;
  /* pienempi arvoista: vanhentunut --app-h ei voi koskaan venyttää kuorta näkyvän alueen yli */
  height: min(var(--app-h, 100dvh), 100dvh);
  min-height: 0;
  max-height: none;
  padding:
    env(safe-area-inset-top, 0px)
    env(safe-area-inset-right, 0px)
    env(safe-area-inset-bottom, 0px)
    env(safe-area-inset-left, 0px);
}

/* Laatan pyöristys ja sisäosa suhteessa laatan kokoon (86 px → 18 / 6 / 14 px kuten ennen) */
.tile { border-radius: calc(var(--tile-size) * 0.21); }
.tile::after {
  inset: calc(var(--tile-size) * 0.07);
  border-radius: calc(var(--tile-size) * 0.163);
}

/* Piilotettu vaihtoehtorivi ei vie tilaa (#choicesBar-säännön !important ohitti .hidden-luokan) */
#choicesBar.hidden { display: none !important; }

/* Arvausrivi kutistuu pois, kun siinä ei ole näkyvää sisältöä → tila laudalle */
.guessbar:not(:has(> :not(.hidden))) { display: none; }

/* ⋯ = pikavalikko: vain kosketuslaitteilla */
.btn-more { display: none; }

/* Play ja Stop yhtenä painikkeena kaikilla laitteilla (▶ Play / ■ Stop soittotilan mukaan).
   Erilliset #btnPlay/#btnStop jäävät DOMiin piilotettuina: näppäimet, eleet ja battle-logiikka käyttävät niitä. */
#btnPlay,
#btnStop { display: none; }
.btn-play-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  white-space: nowrap;
}
.btn-play-toggle.is-playing { background: var(--btn-bg); }

/* —— Tiivis yläpalkki (puhelin ja tabletti) —— */
html[data-compact="1"] .topbar {
  flex-wrap: nowrap;
  gap: 8px;
}
html[data-compact="1"] .topbar h1 {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
html[data-compact="1"] .controls {
  position: relative;
  flex-wrap: nowrap;
  margin-left: auto;
}
html[data-compact="1"] .btn-more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  font-size: 20px;
  line-height: 1;
}
html[data-compact="1"] .controls .btn { min-height: 40px; }

/* Yläpalkki kosketuslaitteilla:
   puhelin  [▶/■] [Next] [🎵] [?] [⋯]
   tabletti [▶/■] [Next] [🎵] [Genres] [?] [⚙] [⋯]
   Muut toiminnot (koko näyttö, transponointi, Rolling …) ovat pikavalikossa. */
html[data-compact="1"] #btnFullscreenTop,
html[data-compact="1"] #transposeQuick,
html[data-compact="1"] #btnRolling { display: none; }
html[data-compact="1"] #btnPlayToggle { order: 1; }
html[data-compact="1"] #btnNext { order: 2; }
html[data-compact="1"] #btnNotesToggle { order: 3; }
html[data-compact="1"] #btnGenres { order: 4; }
html[data-compact="1"] #btnHelpTop { order: 5; }
html[data-compact="1"] #btnSettings { order: 6; }
html[data-compact="1"] #btnMoreTop { order: 7; }
html[data-device="phone"] #btnGenres,
html[data-device="phone"] #btnSettings { display: none; }

/* Puhelin: ei otsikkoa, ohuet reunukset → mahdollisimman paljon tilaa laudalle */
html[data-device="phone"] .topbar h1 { display: none; }
html[data-device="phone"] .top-chrome .top-chrome-inner { padding: 6px 8px 4px; }
html[data-device="phone"] .board-frame > .main-stage.container { padding: 4px 6px 4px; }
html[data-device="phone"] .melody-strip {
  margin: 2px 0;
  padding: 5px;
  border-radius: 10px;
  min-height: 0;
}
html[data-device="phone"] .guessbar { gap: 6px; }

/* Tabletti: kevyemmät reunukset */
html[data-device="tablet"] .top-chrome .top-chrome-inner { padding: 10px 14px 8px; }
html[data-device="tablet"] .board-frame > .main-stage.container { padding: 6px 8px 6px; }
html[data-device="tablet"] .melody-strip { margin: 3px 0; padding: 6px; }

/* Vastausvaihtoehdot puhelimessa: pysty 2×2, vaaka yksi matala rivi */
html[data-device="phone"] #choicesBar {
  gap: 6px;
  margin-top: 4px;
  padding: 0;
}
html[data-device="phone"] #choicesBar .btn {
  min-height: 44px;
  padding: 6px 8px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.2;
}
html[data-device="phone"][data-orient="portrait"] #choicesBar {
  grid-template-columns: repeat(2, 1fr);
}
html[data-device="phone"][data-orient="landscape"] #choicesBar .btn {
  min-height: 38px;
  font-size: 13px;
}
html[data-compact="1"] .controls .btn.icon-small {
  width: 40px;
  min-width: 40px;
  height: 40px;
}

/* Laudan tyhjä alue: tuplanapautus = koko näyttö (app.js), ei selaimen tuplanapautuszoomia */
.main-stage .board-viewport { touch-action: manipulation; }


/* Asetusten sulkupainike: pysyy näkyvissä vieritettäessä */
.settings { position: relative; }
.settings-close {
  position: sticky;
  top: 0;
  float: right;
  z-index: 5;
  min-width: 40px;
  min-height: 40px;
  margin: 0 0 4px 8px;
  font-size: 18px;
  line-height: 1;
}

/* Kosketuslaitteet: asetusrivit rivittyvät, ettei mitään jää näkyvän alueen oikean reunan taakse */
html[data-compact="1"] .settings-row.compact { flex-wrap: wrap; gap: 8px 14px; }
html[data-compact="1"] .settings-row label.switch { min-width: 0; }
html[data-compact="1"] .settings-row { flex-wrap: wrap; }
html[data-compact="1"] .settings-row input[type=range] { flex: 1 1 160px; min-width: 0; }
html[data-device="phone"] .settings-panel-scroll { padding: 6px 8px 24px; }

/* Ilmoitusrivi (flashTopInfo): pitkä ohje rivittyy kapealla näytöllä */
#paletteFlash {
  max-width: calc(100vw - 24px);
  width: max-content;
  white-space: normal;
  text-align: center;
}

/* =========================
   Pikavalikko (static/js/quick-menu.js) – puhelin & tabletti
   ========================= */
.quick-menu {
  position: fixed;
  inset: 0;
  z-index: 2000; /* yläpalkin (200) ja paneelikerroksen (.overlay-layer 1000) päällä */
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.quick-menu.hidden { display: none; }
.qm-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}
.qm-sheet {
  position: relative;
  width: 100%;
  max-width: 640px;
  max-height: min(82%, 640px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  background: rgba(18, 20, 36, 0.98);
  border: 1px solid var(--panel-border);
  border-bottom: none;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.55);
  color: var(--text);
}
.qm-header {
  position: sticky;
  top: -10px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: -10px -12px 4px;
  padding: 10px 12px 6px;
  background: inherit;
  z-index: 1;
}
.qm-title { font-weight: 700; }
.qm-status {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3; /* rivittyy: skin- ja palettinimi näkyvät kapeallakin näytöllä */
}
.qm-close { min-width: 40px; min-height: 40px; font-size: 18px; }
.qm-group h4 {
  margin: 8px 2px 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.qm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 8px;
}
.qm-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 64px;
  padding: 8px 4px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  background: var(--btn-bg);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
.qm-item:active { transform: translateY(1px); filter: brightness(1.15); }
.qm-icon { font-size: 22px; line-height: 1; }
.qm-label { font-size: 12.5px; line-height: 1.2; text-align: center; }
.qm-hint {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
html[data-device="tablet"] .qm-sheet { border-radius: 18px; margin-bottom: 16px; }

/* Ensimmäisen kerran vinkki eleistä (yläpalkin alla, ei peitä vastausnappeja) */
.gesture-hint {
  position: fixed;
  left: 50%;
  top: calc(64px + env(safe-area-inset-top, 0px));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 24px);
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(15, 17, 32, 0.96);
  border: 1px solid var(--panel-border);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  color: var(--text);
  font-size: 14px;
  line-height: 1.35;
  text-align: center;
  z-index: 2100;
}
.gesture-hint strong { margin-right: 6px; }

/* Ohjeen Eleet-osio vain kosketuslaitteilla */
.help-gestures { display: none; margin-bottom: 14px; }
html[data-compact="1"] .help-gestures { display: block; }

/* Pikavalikon nuottinimi-painike: sama "C♯"-merkki kuin yläpalkissa */
.qm-notes .qm-icon { font-weight: 800; font-size: 20px; letter-spacing: -0.02em; }

/* Hz-kerroksen kulmat samat kuin laatan (pyöristys skaalautuu laatan koon mukana) */
.tile-overlay { border-radius: calc(var(--tile-size) * 0.21); }
/* Hz-kerros näyttää jo nuotin nimen → laatan oma nimilappu piiloon, ettei se kuulta läpi */
.tile:has(.tile-overlay) .note-label { visibility: hidden; }

/* =========================
   Aloitusnäyttö (uusi): koti / battle / tutkimustyökalut
   ========================= */
.start-overlay .intro-modal.ss-modal {
  width: min(100%, 940px);
  max-width: 940px;
  padding: 22px 22px 16px;
}
.ss-view.hidden { display: none !important; }

.ss-hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}
.ss-tiles { display: flex; gap: 6px; margin-bottom: 10px; }
.ss-tiles span {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
}
.ss-tiles span:nth-child(1) { background: #ff3b3b; }
.ss-tiles span:nth-child(2) { background: #ffb02e; }
.ss-tiles span:nth-child(3) { background: #7ed321; }
.ss-tiles span:nth-child(4) { background: #1e90ff; }
.ss-tiles span:nth-child(5) { background: #b05cff; }
.ss-title {
  margin: 0;
  font-size: clamp(2rem, 6vw, 3rem);
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1;
}
.ss-tagline { margin: 8px 0 0; color: var(--muted); font-size: clamp(0.95rem, 2.4vw, 1.1rem); }
.ss-hero-actions { display: flex; gap: 8px; }
.ss-icon-btn {
  min-width: 44px;
  min-height: 44px;
  font-size: 18px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ss-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
}
.ss-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.10);
}
.ss-card-primary { border: 2px solid #4c7dff; background: rgba(76, 125, 255, 0.08); }
/* Battle ja Tutkimustyökalut: sama turkoosi reunus (Yksinpeli korostetaan sinisellä) */
.ss-card-tools,
.ss-card-battle { border-color: rgba(58, 209, 255, 0.45); }
.ss-card-head { display: flex; align-items: center; gap: 10px; }
.ss-card-head h2 { margin: 0; font-size: 1.2rem; }
.ss-card-icon { font-size: 1.6rem; line-height: 1; }
.ss-card-desc { margin: 0; color: #cfd6ee; line-height: 1.45; flex: 1 1 auto; }
.ss-card-btn { min-height: 46px; font-size: 1.05rem; font-weight: 700; margin-top: 2px; }
.ss-card-soon {
  align-items: center;
  justify-content: center;
  min-height: 140px;
  border-style: dashed;
  color: var(--muted);
  text-align: center;
}

.ss-chip {
  align-self: flex-start;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: #dfe5f7;
  font: inherit;
  font-size: 0.85rem;
}
button.ss-chip { cursor: pointer; }
button.ss-chip::after { content: " ▾"; opacity: 0.7; }
button.ss-chip:hover { background: rgba(255, 255, 255, 0.12); }
.ss-chip-row { display: flex; flex-wrap: wrap; gap: 6px; }

.ss-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.9rem;
}
.ss-check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.ss-check input { transform: scale(1.2); }

/* Battle- ja työkalunäkymä */
.ss-view-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.ss-view-head h2 { margin: 0; font-size: 1.4rem; }
.ss-label { color: var(--muted); font-size: 0.9rem; padding: 0; margin-bottom: 8px; }
.ss-mode-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  border: none;
  margin: 0 0 14px;
  padding: 0;
}
.ss-mode-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
}
.ss-mode-card input { position: absolute; opacity: 0; pointer-events: none; }
.ss-mode-card span { color: var(--muted); font-size: 0.9rem; }
.ss-mode-card:has(input:checked) { border: 2px solid #4c7dff; background: rgba(76, 125, 255, 0.10); }
.ss-mode-card:has(input:focus-visible) { outline: 2px solid #fff; outline-offset: 2px; }
.ss-names {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.ss-names .field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); }
.ss-names input {
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: #171a2b;
  color: var(--text);
  font-size: 1rem;
}
.ss-battle-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; }
.ss-battle-row select {
  min-height: 40px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: #171a2b;
  color: var(--text);
  font-size: 1rem;
}
.ss-inline-label { color: var(--muted); }
.ss-advanced { margin-bottom: 14px; color: #cfd6ee; }
.ss-advanced summary { cursor: pointer; color: var(--muted); padding: 6px 0; }
.ss-advanced .ss-check { margin: 8px 0; }
.ss-actions { display: flex; justify-content: flex-end; }
.ss-actions .ss-card-btn { min-width: 200px; }

html[data-device="phone"] .start-overlay .intro-modal.ss-modal { padding: 14px 12px 12px; }
html[data-device="phone"] .ss-hero { margin-bottom: 12px; }
html[data-device="phone"] .ss-actions .ss-card-btn { width: 100%; }

/* =========================
   Tutkimustyökalu käynnissä (kuulotesti)
   ========================= */
/* Muistitestissä vastataan neljästä vaihtoehdosta; seuraava kappale tulee testiltä (ei Next-painiketta) */
html[data-tool]:not([data-tool="memory"]) #choicesBar,
html[data-tool] #btnNext { display: none !important; }
.tool-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(58, 209, 255, 0.08);
  border: 1px solid rgba(58, 209, 255, 0.35);
}
.tool-bar-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 260px; }
.tool-bar-text span { color: var(--muted); font-size: 0.9rem; }
.tool-bar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tool-bar-actions .btn { min-height: 44px; font-weight: 700; }

.tool-result {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.6);
}
.tool-result.hidden { display: none; }
.tool-result-card {
  width: min(100%, 520px);
  padding: 20px;
  border-radius: 16px;
  background: rgba(23, 26, 43, 0.98);
  border: 1px solid rgba(58, 209, 255, 0.45);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  color: var(--text);
}
.tool-result-card h3 { margin: 0 0 10px; }
.tool-result-main { margin: 0 0 8px; font-size: clamp(1.8rem, 7vw, 2.4rem); font-weight: 800; }
.tool-result-main #toolResultNote { font-size: 0.55em; color: var(--muted); font-weight: 600; }
.tool-result-detail { margin: 0 0 16px; color: #cfd6ee; line-height: 1.45; }
.tool-result-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.tool-result-actions .btn { min-height: 44px; flex: 1 1 160px; }

/* Soivan laatan kehys: sama kehä kuin ennen, 1 px vahvempi (2 → 3 px).
   Hz-näkymässä tumma .tile-overlay peittäisi ::after-kehän, joten sama kehä piirretään
   kerroksen päälle samaan kohtaan (laatan sisäosan reunaan, inset 7 %). */
.tile.active::after { outline: 3px solid #fff; }
.tile.active .tile-overlay {
  outline: 3px solid #fff;
  outline-offset: calc(var(--tile-size) * -0.07);
}

/* Päävalikko-painike (⌂): yläpalkin ensimmäinen kaikilla laitteilla */
.btn-home {
  min-width: 48px;
  padding-block: 2px;
  padding-inline: 6px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
/* Piirretty talokuvake (harjakatto, seinät, ovi) – ei sekoitu ylänuoleen kuten ⌂-merkki */
.icon-house { width: 26px; height: 26px; display: block; }
.qm-icon .icon-house { width: 24px; height: 24px; margin: 0 auto; }
html[data-compact="1"] #btnHome { order: 0; }

/* =========================
   Laudan latausnäkymä (labyrintin valmistelu)
   ========================= */
.board-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: min(60vh, 420px);
  padding: 24px 16px;
  text-align: center;
  color: var(--text);
}
.board-loading-tiles { display: flex; gap: 8px; margin-bottom: 6px; }
.board-loading-tiles span {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  opacity: 0.35;
  animation: board-loading-pulse 1.25s ease-in-out infinite;
}
.board-loading-tiles span:nth-child(1) { background: #ff3b3b; animation-delay: 0s; }
.board-loading-tiles span:nth-child(2) { background: #ffb02e; animation-delay: .15s; }
.board-loading-tiles span:nth-child(3) { background: #7ed321; animation-delay: .30s; }
.board-loading-tiles span:nth-child(4) { background: #1e90ff; animation-delay: .45s; }
.board-loading-tiles span:nth-child(5) { background: #b05cff; animation-delay: .60s; }
@keyframes board-loading-pulse {
  0%, 100% { opacity: 0.35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-6px); }
}
@media (prefers-reduced-motion: reduce) {
  .board-loading-tiles span { animation: none; opacity: 0.9; }
}
.board-loading-title { font-size: clamp(1.15rem, 4vw, 1.5rem); font-weight: 800; }
.board-loading-detail { max-width: 34ch; color: #cfd6ee; line-height: 1.45; }
.board-loading-time { min-height: 1.2em; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Labyrintin kappaleen nimi alarivillä: keskitetty ja isompi fontti */
.labyrinth-info:not(.hidden) {
  display: flex;
  justify-content: center;
}
.labyrinth-title-box {
  min-width: min(100%, 320px);
  max-width: 100%;
  padding: 14px 28px;
  min-height: 0;
  font-size: clamp(20px, 3.2vw, 32px);
  font-weight: 800;
  line-height: 1.25;
}
html[data-device="phone"] .labyrinth-info { margin-top: 6px; }
html[data-device="phone"] .labyrinth-title-box { width: 100%; padding: 10px 16px; font-size: clamp(18px, 5.5vw, 24px); }

/* Yksinpeli-battle: yhteenvedosta piiloon pelaajan 2 rivit ja sarakkeet sekä voittajateksti */
.battle-solo #battleSummaryBody tr:nth-child(n+2),
.battle-solo #battleSummaryLabyrinthOverviewBody tr:nth-child(n+2),
.battle-solo #battleSummarySegmentDuelOverviewBody tr:nth-child(n+2),
.battle-solo #labyrinthDetailP2Header,
.battle-solo #segmentDuelDetailP2Header,
.battle-solo .battle-summary-labyrinth thead tr:nth-child(2) > th:nth-child(n+4),
.battle-solo .battle-summary-labyrinth tbody td:nth-child(n+4),
.battle-solo .battle-summary-winner { display: none; }
.ss-optional { font-size: 0.85em; color: var(--muted); }

/* Battle-näkymän pelaajakentät samalle tasolle: otsikot yhdelle riville, kentät tasattu alareunaan */
.ss-names { align-items: end; }
.ss-names .field > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ss-names { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ss-names input { min-width: 0; width: 100%; }

/* =========================
   Työpöytä: enemmän tilaa pelilaudalle
   ========================= */
/* Skinien koristekehys ohuemmaksi (oli 48 px + 6 px): kuvio säilyy, tilaa jää laudalle */
html[data-device="desktop"][data-ornament="1"] .board-frame > .main-stage.container {
  --frame: clamp(14px, 1.5vw, 26px);
  padding: calc(4px + var(--frame));
}

/* Battle-otsikko tiiviimmäksi (kaikki laitteet) */
.labyrinth-player-top {
  margin: 4px 0 6px;
  padding: 6px 14px;
  font-size: 1.1rem;
}
.labyrinth-player-top .labyrinth-player-name { font-size: 1.25rem; }
.labyrinth-song-order { margin-top: 2px; font-size: 0.95rem; }
/* Työpöydällä kappaleen järjestys samalle riville → otsikko yhdelle riville */
html[data-device="desktop"] .labyrinth-player-top .labyrinth-song-order {
  display: inline;
  margin: 0 0 0 12px;
}
html[data-device="desktop"] .labyrinth-player-top .labyrinth-song-order::before {
  content: "· ";
  color: rgba(255, 255, 255, 0.45);
}

/* =========================
   Segment Duel: segmentin alku (nuoli) ja loppu (ruutulippu)
   ========================= */
.tile .segment-start-marker {
  position: absolute;
  top: 3px;
  left: 3px;
  width: clamp(16px, calc(var(--tile-size) * 0.42), 32px);
  height: clamp(16px, calc(var(--tile-size) * 0.42), 32px);
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6), 0 0 10px rgba(34, 197, 94, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 6; /* myös Hz-kerroksen (z 5) päällä */
}
.tile .segment-start-arrow {
  display: block;
  color: #fff;
  font-size: clamp(10px, calc(var(--tile-size) * 0.26), 20px);
  font-weight: 900;
  line-height: 1;
  transform-origin: 50% 50%;
}
/* Loppulaatan ruutulippu: labyrintin merkki, pyöristys laatan mukaan ja Hz-kerroksen päällä */
.tile .labyrinth-end-marker { border-radius: calc(var(--tile-size) * 0.21); }
.tile .segment-end-marker { z-index: 6; }

/* Pikavalikko kotinäytöltä: pelitoiminnot piiloon (display-sääntö ohittaisi hidden-attribuutin) */
.quick-menu .qm-item[hidden] { display: none; }
.quick-menu.qm-home .qm-hint { display: none; }

/* =========================
   Melodiasta puheeseen (tutkimustyökalu)
   ========================= */
.ss-speech-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 10px; margin: 10px 0 4px; }
.ss-speech-grid select, .ss-speech-grid input { width: 100%; }
html[data-device="phone"] .ss-speech-grid { grid-template-columns: 1fr; }
#startViewSpeech .ss-mode-cards { margin-top: 12px; }
#speechHzRow { flex-wrap: wrap; }
#speechHzRow input[type="number"] { width: 5.5em; }
#speechHzRow.is-disabled { opacity: 0.45; }
#speechHzRow .ss-chip { cursor: pointer; }

.speech-bar { align-items: center; }
.speech-levels { display: flex; flex-wrap: wrap; gap: 6px; }
.speech-levels .speech-level { min-width: 44px; min-height: 44px; font-weight: 800; }
.speech-levels .speech-level.is-active {
  background: #3ad1ff; color: #0b1020; border-color: #3ad1ff;
}
.speech-slider {
  display: flex; align-items: center; gap: 8px; flex: 1 1 260px; min-width: 220px;
  font-size: 0.75rem; font-weight: 800; letter-spacing: 0.06em; color: var(--muted);
}
.speech-slider input[type="range"] { flex: 1 1 auto; min-width: 100px; }
.speech-slider output { min-width: 4.2em; text-align: right; color: var(--text); font-size: 0.95rem; }
#speechInfo { font-variant-numeric: tabular-nums; }

/* =========================
   Musiikillinen muistitesti
   ========================= */
.memory-genres { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 4px; }
.memory-genre { cursor: pointer; display: inline-flex; align-items: center; gap: 6px; user-select: none; }
.memory-genre input { margin: 0; }
.memory-genre:has(input:checked) { border-color: #3ad1ff; background: rgba(58, 209, 255, 0.16); }
.memory-params { display: grid; gap: 8px; margin: 8px 0; }
/* Teksti | kenttä | yksikkö – kentät samassa linjassa lähellä oikean reunan yksikköä */
.memory-params label { display: grid; grid-template-columns: 1fr 5em 1.2em; align-items: center; gap: 8px; }
.memory-params input { width: 100%; box-sizing: border-box; grid-column: 2; }
.memory-params .memory-unit { grid-column: 3; }
.memory-clock { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text); margin-left: 6px; }

.memory-result-card { width: min(100%, 680px); max-height: calc(var(--app-h, 100vh) - 32px); overflow-y: auto; }
.memory-score-row { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; }
.memory-score-main { margin: 0; font-size: clamp(2rem, 8vw, 2.8rem); font-weight: 800; }
.memory-score-row .tool-result-detail { margin: 2px 0 0; }
.memory-badge {
  flex: 0 0 auto; min-width: 92px; padding: 10px 14px; border-radius: 999px; text-align: center;
  font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; color: #0b1020;
}
.memory-badge.memory-green { background: #22c55e; }
.memory-badge.memory-yellow { background: #facc15; }
.memory-badge.memory-red { background: #ef4444; color: #fff; }
.memory-table-wrap { max-height: 260px; overflow-y: auto; margin-bottom: 10px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.08); }
.memory-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.memory-table th, .memory-table td { padding: 6px 8px; text-align: left; border-bottom: 1px solid rgba(255,255,255,0.06); }
.memory-table th { position: sticky; top: 0; background: rgba(23, 26, 43, 0.98); color: var(--muted); font-weight: 700; }
.memory-table td:nth-child(n+4) { text-align: right; font-variant-numeric: tabular-nums; }
.memory-table tr.is-correct td:nth-child(3) { color: #4ade80; }
.memory-table tr.is-wrong td:nth-child(3) { color: #f87171; }
.memory-note { margin: 0 0 14px; font-size: 0.85rem; color: var(--muted); }

/* Muistitesti: asiakas, paketit, käsivalinta ja tuttuuskartoitus */
.memory-client { margin: 8px 0 4px; }
.memory-client input { width: 100%; max-width: 320px; }
#memoryClientActions a.ss-chip { text-decoration: none; }
.memory-panel {
  margin: 10px 0; padding: 10px 12px; border-radius: 12px;
  background: rgba(58, 209, 255, 0.06); border: 1px solid rgba(58, 209, 255, 0.3);
}
.memory-panel-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.memory-list { max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.memory-row { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 8px; font-size: 0.92rem; }
.memory-row:nth-child(odd) { background: rgba(255, 255, 255, 0.03); }
.memory-row > span { flex: 1 1 auto; min-width: 0; }
.memory-survey-row { flex-wrap: wrap; }
.memory-seg { display: inline-flex; gap: 4px; flex: 0 0 auto; }
.memory-seg-btn {
  min-height: 34px; padding: 4px 10px; border-radius: 999px; cursor: pointer; font-weight: 700; font-size: 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.2); background: transparent; color: var(--text);
}
.memory-seg-btn.memory-seg-known.is-on { background: #22c55e; border-color: #22c55e; color: #0b1020; }
.memory-seg-btn.memory-seg-unsure.is-on { background: #facc15; border-color: #facc15; color: #0b1020; }
.memory-seg-btn.memory-seg-unknown.is-on { background: #64748b; border-color: #64748b; color: #fff; }
#memoryPackageName { flex: 1 1 200px; min-width: 0; }

/* Kehityskuvaaja */
.memory-chart-wrap { margin: 4px 0 10px; }
.memory-chart { width: 100%; height: auto; display: block; }
.memory-chart .mc-green { fill: rgba(34, 197, 94, 0.14); }
.memory-chart .mc-yellow { fill: rgba(250, 204, 21, 0.12); }
.memory-chart .mc-red { fill: rgba(239, 68, 68, 0.1); }
.memory-chart .mc-line { fill: none; stroke: #3ad1ff; stroke-width: 2.5; }
.memory-chart .mc-dot { stroke: #0b1020; stroke-width: 1.5; }
.memory-chart .mc-dot-green { fill: #22c55e; }
.memory-chart .mc-dot-yellow { fill: #facc15; }
.memory-chart .mc-dot-red { fill: #ef4444; }
.memory-chart .mc-axis { fill: var(--muted); font-size: 11px; }
#lnkMemoryResultCsv { text-decoration: none; display: inline-flex; align-items: center; }

/* Tulosta / PDF: vain muistitestin tulos, vaalealla pohjalla */
@media print {
  body:has(#memoryResult:not(.hidden)) > *:not(#memoryResult) { display: none !important; }
  #memoryResult { position: static !important; background: #fff !important; padding: 0 !important; }
  #memoryResult .tool-result-card {
    max-height: none !important; overflow: visible !important; width: 100% !important;
    background: #fff !important; color: #000 !important; border: 0 !important; box-shadow: none !important;
  }
  #memoryResult .tool-result-actions { display: none !important; }
  #memoryResult .memory-table-wrap { max-height: none !important; overflow: visible !important; border-color: #ccc !important; }
  #memoryResult .memory-table th { position: static; background: #fff !important; color: #000 !important; }
  #memoryResult .tool-result-detail, #memoryResult .memory-note, #memoryResult .mc-axis { color: #333 !important; fill: #333 !important; }
  #memoryResult .memory-badge { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #memoryResult svg * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Tuloskortit kapealla näytöllä (puhelin): taulukko mahtuu leveyteen ilman sivuttaisvieritystä.
   Ratkaisevat sarakkeet (oikein / väärät äänet) ovat ensin, aika viimeisenä. */
@media (max-width: 600px) {
  .battle-summary-modal { width: calc(100vw - 16px); padding: 16px 10px 14px; border-radius: 14px; }
  .battle-summary-modal h2 { font-size: 20px; }
  .battle-summary-table { font-size: 13px; }
  .battle-summary-table th,
  .battle-summary-table td { padding: 6px 5px; white-space: normal; overflow-wrap: anywhere; }
  .battle-summary-table th { font-size: 12px; line-height: 1.2; }
  .battle-summary-table td.score-total { font-size: 15px; }
  .battle-summary-table td:not(.player) { text-align: center; font-variant-numeric: tabular-nums; }
  .memory-table { font-size: 12.5px; }
  .memory-table th, .memory-table td { padding: 5px 4px; }
  .memory-table th { line-height: 1.2; }
  .memory-score-row { gap: 10px; }
  .memory-badge { min-width: 0; padding: 8px 10px; font-size: 0.8rem; }
}

/* ===== Pelimuotojen opastus (mode-guide.js) ===== */
/* Aloitusnäkymän (.overlay-layer, z 1000) ja battle-modaalien päällä */
.mode-guide-backdrop{ z-index: 1500; padding: 16px; }
.mode-guide-modal{
  width: min(100%, 520px);
  max-height: min(calc(100dvh - 32px), calc(100vh - 32px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.mode-guide-head{ display:flex; align-items:center; gap:10px; }
.mode-guide-icon{ font-size: 1.8rem; line-height: 1; }
.mode-guide-head h3{ margin: 4px 0; }
.mode-guide-lead{ margin: 8px 0 10px; }
.mode-guide-steps{ margin: 0 0 10px; padding-left: 1.4em; color:#cfd6ee; line-height:1.45; }
.mode-guide-steps li{ margin: 4px 0; }
.mode-guide-tip{
  margin: 0 0 6px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255,255,255,.06);
  font-size: .92rem;
}
/* Tuleva apu-animaatio sanallisen opastuksen rinnalle */
.mode-guide-anim{
  margin: 0 0 10px;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(0,0,0,.25);
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mode-guide-anim img,
.mode-guide-anim video{ display:block; max-width:100%; max-height: 240px; }
.mode-guide-footer{
  display:flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin-top: 8px;
}
.mode-guide-footer .modal-actions{ margin-top: 0; margin-left: auto; }
.mode-guide-check{ font-size: .9rem; cursor: pointer; }
.help-guides-reset{ margin-top: 14px; text-align: right; }

/* ===== Klassinen battle: vuoronvaihto ja vuorossa olevan pelaajan väri (P1 sininen, P2 vihreä) ===== */
.battle-hud.battle-hud-p1 #battleHudPlayer{ color:#93c5fd; font-weight:700; }
.battle-hud.battle-hud-p2 #battleHudPlayer{ color:#86efac; font-weight:700; }
.battle-handover-modal.battle-handover-classic{
  width: min(100%, 440px);
  text-align: center;
  padding: 28px 22px 20px;
}
.battle-handover-classic h3{ font-size: 2rem; margin: 0 0 10px; }
.battle-handover-classic .modal-actions{ justify-content: center; margin-top: 18px; }
.battle-handover-classic .modal-actions .btn{ font-size: 1.1rem; padding: 10px 22px; }
.battle-handover-modal.battle-handover-p1{
  background: linear-gradient(135deg, rgba(59,130,246,.55), rgba(30,58,138,.9));
  border: 2px solid rgba(96,165,250,.8);
}
.battle-handover-modal.battle-handover-p2{
  background: linear-gradient(135deg, rgba(34,197,94,.5), rgba(20,83,45,.9));
  border: 2px solid rgba(74,222,128,.8);
}
.mode-guide-warning{
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(220, 38, 38, .18);
  border: 1px solid rgba(248, 113, 113, .6);
  color: #fecaca;
  font-size: .93rem;
  line-height: 1.45;
}

/* ===== Battle – Huutokauppa ===== */
.auction-bar.auction-p1{
  background: linear-gradient(135deg, rgba(59,130,246,.28), rgba(30,58,138,.38));
  border: 2px solid rgba(96,165,250,.7);
}
.auction-bar.auction-p2{
  background: linear-gradient(135deg, rgba(34,197,94,.24), rgba(20,83,45,.38));
  border: 2px solid rgba(74,222,128,.7);
}
.auction-bar .tool-bar-text strong{ font-size: 1.05rem; }
.auction-bar .tool-bar-actions{ display:flex; flex-wrap: wrap; align-items:center; gap: 8px; }
.auction-stepper{ display:inline-flex; align-items:center; gap: 6px; }
.auction-stepper .btn{ min-width: 40px; font-size: 1.2rem; padding: 4px 10px; }
.auction-value{ min-width: 2.2ch; text-align:center; font-size: 1.6rem; font-weight: 800; }
/* Avaamaton laatta: ei väriä, ei nuottinimeä. Skinit piirtävät värin ::before/::after-kerroksiin
   --tile-color-muuttujasta (inline style), joten muuttuja ylikirjoitetaan !important-säännöllä. */
.tile.auction-covered{
  --tile-color: #2a2f44 !important;
  background: #2a2f44 !important;
  background-image: none !important;
  border-color: rgba(255,255,255,.08) !important;
  box-shadow: none !important;
  color: transparent !important;
  filter: none !important;
}
.tile.auction-covered > *{ visibility: hidden !important; }

/* Huutokauppa, soittovaihe: avatut laatat korostettuina, loput varjostettuina kuten Segment Duelissa */
.tile.auction-open {
  outline: 3px solid rgba(255, 200, 0, 0.8);
  outline-offset: -2px;
}
.tile.auction-locked {
  opacity: 0.4;
  filter: grayscale(0.5);
  cursor: not-allowed;
}
.tile.auction-locked .note-label { visibility: hidden; }
/* Laatassa on aina tyhjä .note-label: ei tummaa pohjaa, kun nuottinimet ovat pois päältä */
.tile .note-label:empty { display: none; }
