/* Salikirja — ulkoasu.
   Suunniteltu käteen salilla: isot tekstit, isot painikkeet, vahva kontrasti. */

:root {
  --skaala: 1;
  --pohja:    #10131a;
  --pinta:    #191d27;
  --pinta2:   #232936;
  --reuna:    #333c4d;
  --teksti:   #f2f5fa;
  --himmea:   #a7b2c6;
  --korostus: #4cc2ff;
  --korostus-tumma: #0a4a68;
  --ok:       #46d67f;
  --varoitus: #ffb020;
  --vaara:    #ff5c5c;
  --varjo: 0 2px 10px rgba(0,0,0,.35);
  --pyoristys: 14px;
}

:root[data-teema="vaalea"] {
  --pohja:    #f4f6fa;
  --pinta:    #ffffff;
  --pinta2:   #e9edf5;
  --reuna:    #c8d0de;
  --teksti:   #11151d;
  --himmea:   #55617a;
  --korostus: #0a6ebd;
  --korostus-tumma: #cfe6f8;
  --ok:       #12873f;
  --varoitus: #a86400;
  --vaara:    #c62828;
  --varjo: 0 2px 8px rgba(20,30,50,.12);
}

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

html { font-size: calc(17px * var(--skaala)); }

body {
  margin: 0;
  background: var(--pohja);
  color: var(--teksti);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
  overscroll-behavior-y: contain;
}

/* ---------- Rakenne ---------- */

header.ylapalkki {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: .6rem;
  padding: max(.7rem, env(safe-area-inset-top)) .9rem .7rem;
  background: var(--pinta);
  border-bottom: 1px solid var(--reuna);
}
header.ylapalkki h1 { font-size: 1.25rem; margin: 0; flex: 1; font-weight: 700; letter-spacing: -.01em; }
header.ylapalkki .alaotsikko { display: block; font-size: .8rem; font-weight: 500; color: var(--himmea); }

main {
  padding: 1rem .9rem calc(6.5rem + env(safe-area-inset-bottom));
  max-width: 900px; margin: 0 auto;
}

nav.alapalkki {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: space-around;
  background: var(--pinta);
  border-top: 1px solid var(--reuna);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.alapalkki button {
  flex: 1; min-height: 62px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: none; color: var(--himmea);
  font-size: .72rem; font-weight: 600; font-family: inherit;
  padding: .35rem .1rem; cursor: pointer;
}
nav.alapalkki button svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
nav.alapalkki button[aria-current="page"] { color: var(--korostus); }
nav.alapalkki button .merkki {
  position: absolute; transform: translate(18px, -16px);
  width: 9px; height: 9px; border-radius: 50%; background: var(--ok);
}

/* ---------- Perusosat ---------- */

h2 { font-size: 1.15rem; margin: 1.4rem 0 .7rem; }
h2:first-child { margin-top: 0; }
h3 { font-size: 1rem; margin: 0 0 .4rem; }
p  { margin: .4rem 0; }
.himmea { color: var(--himmea); }
.pieni  { font-size: .85rem; }
.iso    { font-size: 1.5rem; font-weight: 700; }
.keski  { text-align: center; }
.rivi   { display: flex; align-items: center; gap: .6rem; }
.rivi.valissa { justify-content: space-between; }
.kasvaa { flex: 1; min-width: 0; }
.pinoa  { display: flex; flex-direction: column; gap: .7rem; }
.katkaise { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.kortti {
  background: var(--pinta);
  border: 1px solid var(--reuna);
  border-radius: var(--pyoristys);
  padding: .9rem;
  box-shadow: var(--varjo);
}
.kortti + .kortti { margin-top: .7rem; }
.kortti.klikattava { cursor: pointer; }
.kortti.klikattava:active { background: var(--pinta2); }

.tyhja {
  text-align: center; color: var(--himmea);
  padding: 2.5rem 1rem; border: 2px dashed var(--reuna); border-radius: var(--pyoristys);
}
.tyhja svg { width: 46px; height: 46px; stroke: currentColor; fill: none; stroke-width: 1.5; opacity: .6; margin-bottom: .5rem; }

button, .nappi {
  font-family: inherit; font-size: 1rem; font-weight: 600;
  border-radius: 11px; border: 1px solid var(--reuna);
  background: var(--pinta2); color: var(--teksti);
  padding: .7rem 1rem; min-height: 48px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
}
button:active { transform: scale(.98); }
button.ensisijainen { background: var(--korostus); border-color: var(--korostus); color: #04121b; }
:root[data-teema="vaalea"] button.ensisijainen { color: #fff; }
button.vaara { color: var(--vaara); border-color: var(--vaara); background: transparent; }
button.hillitty { background: transparent; }
button.leveä, button.levea { width: 100%; }
button.iso-nappi { min-height: 60px; font-size: 1.1rem; }
button.pieni-nappi { min-height: 38px; padding: .3rem .6rem; font-size: .85rem; border-radius: 9px; }
button svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
button:disabled { opacity: .45; cursor: not-allowed; }

input, select, textarea {
  font-family: inherit; font-size: 1rem;
  background: var(--pohja); color: var(--teksti);
  border: 1px solid var(--reuna); border-radius: 10px;
  padding: .65rem .7rem; min-height: 48px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 3px solid var(--korostus); outline-offset: 1px; }
label { display: block; font-size: .85rem; font-weight: 600; color: var(--himmea); margin: .7rem 0 .25rem; }
textarea { min-height: 80px; resize: vertical; }

.merkkaus {
  display: inline-block; font-size: .72rem; font-weight: 700;
  padding: .15rem .5rem; border-radius: 999px;
  background: var(--pinta2); color: var(--himmea); border: 1px solid var(--reuna);
  white-space: nowrap;
}
.merkkaus.korostettu { background: var(--korostus-tumma); color: var(--korostus); border-color: var(--korostus); }
.merkkaus.ok { color: var(--ok); border-color: var(--ok); background: transparent; }

/* ---------- Asennussuositus ---------- */

.asennuspalkki {
  border-color: var(--korostus);
  background: linear-gradient(180deg, var(--korostus-tumma), var(--pinta));
  margin-bottom: 1rem;
}
.asennuskuva {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 12px;
  background: var(--korostus); color: #04121b;
  display: flex; align-items: center; justify-content: center;
}
:root[data-teema="vaalea"] .asennuskuva { color: #fff; }
.asennuskuva svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Mittarit ---------- */

.mittarit { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: .6rem; }
.mittari {
  background: var(--pinta); border: 1px solid var(--reuna); border-radius: var(--pyoristys);
  padding: .7rem .5rem; text-align: center;
}
.mittari .arvo { font-size: 1.35rem; font-weight: 800; line-height: 1.1; display: block; }
.mittari .nimi { font-size: .72rem; color: var(--himmea); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Sarjarivit ---------- */

.sarjaotsikot, .sarjarivi {
  display: grid;
  grid-template-columns: 2.2rem 1fr 1fr 3.2rem;
  gap: .45rem; align-items: center;
}
.sarjaotsikot {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--himmea); font-weight: 700; padding: .3rem .1rem;
}
.sarjarivi { margin-bottom: .45rem; }
.sarjarivi .numero {
  text-align: center; font-weight: 800; color: var(--himmea); font-size: .95rem;
}
.sarjarivi input {
  text-align: center; font-size: 1.1rem; font-weight: 700; padding: .5rem .2rem; min-height: 50px;
}
.sarjarivi.tehty input { border-color: var(--ok); color: var(--ok); }
.sarjarivi .kuittaus {
  min-height: 50px; width: 100%; padding: 0; border-radius: 10px;
  background: var(--pinta2); border: 1px solid var(--reuna);
}
.sarjarivi.tehty .kuittaus { background: var(--ok); border-color: var(--ok); color: #052c14; }
.sarjarivi .kuittaus svg { width: 22px; height: 22px; stroke-width: 3; }

/* ---------- Lepoajastin ---------- */

.lepopalkki {
  position: fixed; left: 0; right: 0; bottom: calc(62px + env(safe-area-inset-bottom));
  z-index: 45; background: var(--korostus-tumma);
  border-top: 2px solid var(--korostus);
  padding: .6rem .9rem; display: flex; align-items: center; gap: .7rem;
}
.lepopalkki .aika { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--korostus); min-width: 4.2rem; }
.lepopalkki .kaista { flex: 1; height: 8px; border-radius: 4px; background: rgba(255,255,255,.15); overflow: hidden; }
.lepopalkki .kaista span { display: block; height: 100%; background: var(--korostus); transition: width .3s linear; }

/* ---------- Kaaviot ---------- */

.kaavio { width: 100%; height: auto; display: block; overflow: visible; }
.palkkilista { display: flex; flex-direction: column; gap: .5rem; }
.palkkirivi .yla { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: .2rem; }
.palkkirivi .ura { height: 12px; background: var(--pinta2); border-radius: 6px; overflow: hidden; }
.palkkirivi .ura span { display: block; height: 100%; background: var(--korostus); border-radius: 6px; }

/* ---------- Modaali ---------- */

.peite {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,.65);
  display: flex; align-items: flex-end; justify-content: center;
}
.modaali {
  background: var(--pinta); width: 100%; max-width: 900px;
  max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; border-top: 1px solid var(--reuna);
  padding: 1rem .9rem calc(1.4rem + env(safe-area-inset-bottom));
  animation: nouse .18s ease-out;
}
@keyframes nouse { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.modaali .kahva { width: 44px; height: 5px; border-radius: 3px; background: var(--reuna); margin: 0 auto .8rem; }
.modaali h2 { margin-top: 0; }

/* ---------- Suodattimet ---------- */

.sirut { display: flex; gap: .4rem; overflow-x: auto; padding: .1rem .1rem .5rem; scrollbar-width: none; }
.sirut::-webkit-scrollbar { display: none; }
.sirut button {
  min-height: 40px; padding: .35rem .8rem; font-size: .85rem; border-radius: 999px; white-space: nowrap;
}
.sirut button[aria-pressed="true"] { background: var(--korostus); border-color: var(--korostus); color: #04121b; }
:root[data-teema="vaalea"] .sirut button[aria-pressed="true"] { color: #fff; }

.lista-rivi {
  display: flex; align-items: center; gap: .7rem;
  padding: .8rem .2rem; border-bottom: 1px solid var(--reuna); cursor: pointer;
}
.lista-rivi:last-child { border-bottom: none; }
.lista-rivi:active { background: var(--pinta2); }
.lista-rivi .nuoli { color: var(--himmea); }

.ilmoitus {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 80; background: var(--pinta2); color: var(--teksti);
  border: 1px solid var(--reuna); border-radius: 999px; padding: .6rem 1.1rem;
  font-weight: 600; box-shadow: var(--varjo); max-width: 90vw; text-align: center;
  animation: nouse .18s ease-out;
}

@media (min-width: 700px) {
  .mittarit { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
  .peite { align-items: center; }
  .modaali { border-radius: 18px; max-height: 86vh; }
}
