:root {
  --text: #202122;
  --muted: #54595d;
  --link: #3366cc;
  --link-new: #d73333;
  --border: #a2a9b1;
  --border-light: #eaecf0;
  --bg: #ffffff;
  --bg-soft: #f8f9fa;
  --header-blue: #eaf3ff;
  --serif: 'Linux Libertine', 'Georgia', 'Times', serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 16px; line-height: 1.6;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
a.new { color: var(--link-new); }

/* ---------- Yläpalkki ---------- */
.header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  height: 54px; padding: 0 12px;
  background: #fff; border-bottom: 1px solid var(--border-light);
}
.header .menu, .header .search-btn {
  width: 40px; height: 40px; border: 0; background: none; padding: 8px;
  cursor: pointer; color: var(--text); flex: none;
}
.header .brand { display: flex; align-items: center; gap: 8px; color: var(--text); flex: 1; min-width: 0; }
.header .brand:hover { text-decoration: none; }
.header .brand img { width: 30px; height: 30px; }
.header .brand span { font-family: var(--serif); font-size: 22px; letter-spacing: 0.5px; }

/* Hakunäkymä */
.search-overlay {
  display: none; position: fixed; inset: 0; z-index: 20; background: #fff;
}
.search-overlay.open { display: block; }
.search-bar {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px;
  border-bottom: 1px solid var(--border-light);
}
.search-bar input {
  flex: 1; font-size: 17px; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 2px; outline: none; font-family: var(--sans);
}
.search-bar input:focus { border-color: var(--link); box-shadow: inset 0 0 0 1px var(--link); }
.search-bar button { border: 0; background: none; font-size: 15px; color: var(--link); padding: 10px 6px; cursor: pointer; }
.suggestions { list-style: none; margin: 0; padding: 0; }
.suggestions li a {
  display: flex; gap: 12px; align-items: center;
  padding: 10px 14px; border-bottom: 1px solid var(--border-light); color: var(--text);
}
.suggestions li a:hover { background: var(--bg-soft); text-decoration: none; }
.suggestions .thumb {
  width: 44px; height: 44px; flex: none; border-radius: 2px; background: var(--bg-soft) center/cover;
  border: 1px solid var(--border-light);
}
.suggestions .t { font-weight: 600; }
.suggestions .d { font-size: 13px; color: var(--muted); line-height: 1.3; }
.suggestions mark { background: none; font-weight: 800; color: inherit; }

/* Sivuvalikko */
.drawer-bg { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; }
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: 270px; max-width: 80vw; z-index: 31;
  background: #fff; transform: translateX(-100%); transition: transform .2s ease;
  padding: 16px 0; box-shadow: 2px 0 8px rgba(0,0,0,.15);
}
.drawer.open { transform: none; }
.drawer.open + .drawer-bg { display: block; }
.drawer a { display: block; padding: 12px 22px; color: var(--text); font-size: 15px; }
.drawer a:hover { background: var(--bg-soft); text-decoration: none; }
.drawer hr { border: 0; border-top: 1px solid var(--border-light); margin: 8px 0; }

/* ---------- Sisältö ---------- */
main { max-width: 960px; margin: 0 auto; padding: 0 16px 24px; }
h1.title {
  font-family: var(--serif); font-weight: normal; font-size: 30px; line-height: 1.25;
  margin: 18px 0 2px; padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
.tagline { font-size: 13px; color: var(--muted); margin: 6px 0 14px; }
.lead { margin-top: 0; }
p { margin: 0.5em 0 0.9em; }
ul { padding-left: 1.4em; margin: 0.3em 0 0.9em; }
li { margin-bottom: 0.2em; }
h3 { font-size: 17px; margin: 1.1em 0 0.3em; }

/* Taitettavat osiot kuten mobiili-Wikipediassa */
details.section { border-bottom: 1px solid var(--border-light); }
details.section > summary {
  list-style: none; cursor: pointer;
  font-family: var(--serif); font-size: 23px; padding: 10px 0 8px;
  display: flex; align-items: center; gap: 8px;
}
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::before {
  content: ''; width: 9px; height: 9px; flex: none; margin: 0 4px 4px 2px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform .15s;
}
details.section[open] > summary::before { transform: rotate(45deg); margin-bottom: 8px; }
details.section > .body { padding-bottom: 10px; }

/* Infoboksi */
.infobox {
  width: 100%; border: 1px solid var(--border); background: var(--bg-soft);
  border-collapse: collapse; font-size: 14px; line-height: 1.45; margin: 4px 0 16px;
}
.infobox th, .infobox td { padding: 5px 8px; vertical-align: top; text-align: left; }
.infobox th { width: 38%; }
.infobox .ib-title { font-size: 19px; font-weight: bold; text-align: center; padding: 8px; }
.infobox .ib-img { text-align: center; padding: 4px 8px 8px; }
.infobox .ib-img img { width: 100%; max-width: 260px; height: auto; display: block; margin: 0 auto 4px; border: 1px solid var(--border-light); }
.infobox .ib-img small { color: var(--muted); }
.infobox .ib-head { background: var(--header-blue); text-align: center; font-weight: bold; }

sup.ref { font-size: 11px; line-height: 0; }
sup.ref a { white-space: nowrap; }
.cn { font-size: 11px; font-style: italic; white-space: nowrap; }
ol.refs { font-size: 14px; padding-left: 1.8em; }
ol.refs li:target { background: #eaf3ff; }

.hatnote { font-style: italic; color: var(--muted); padding-left: 1.4em; margin: 0 0 12px; font-size: 15px; }
.disambig-note {
  margin-top: 22px; padding: 10px 12px; border-top: 1px solid var(--border);
  color: var(--muted); font-size: 14px; font-style: italic;
}
.box { border: 1px solid var(--border-light); background: var(--bg-soft); padding: 12px 14px; margin: 14px 0; }
.box h2 { font-family: var(--serif); font-weight: normal; font-size: 21px; margin: 0 0 6px; border-bottom: 1px solid var(--border); padding-bottom: 3px; }
.cats { border: 1px solid var(--border); background: var(--bg-soft); padding: 6px 10px; font-size: 13px; margin-top: 20px; }
.cats a { margin-right: 4px; }

/* Täydennettävät kohdat: näkyvät keltaisina, ettei mikään unohdu */
.taydenna { background: #ffeb3b; color: #000; padding: 0 4px; font-weight: bold; }

/* Alatunniste */
footer {
  max-width: 960px; margin: 10px auto 0; padding: 16px; border-top: 1px solid var(--border-light);
  font-size: 13px; color: var(--muted); background: var(--bg-soft);
}
footer .logo-line { font-family: var(--serif); font-size: 20px; color: var(--text); margin-bottom: 6px; }

@media (min-width: 760px) {
  .infobox { float: right; width: 300px; margin: 0 0 14px 18px; }
  h1.title { font-size: 34px; }
}

/* ---------- Kielet ---------- */
[data-lang] { display: none; }
body.lang-fi [data-lang="fi"], body.lang-sv [data-lang="sv"], body.lang-en [data-lang="en"] { display: block; }
.header .lang-btn { width: 40px; height: 40px; border: 0; background: none; padding: 8px; cursor: pointer; color: var(--text); flex: none; }
.lang-menu {
  display: none; position: fixed; top: 50px; right: 10px; z-index: 25; min-width: 180px;
  background: #fff; border: 1px solid var(--border); border-radius: 2px; box-shadow: 0 2px 8px rgba(0,0,0,.18); padding: 6px 0;
}
.lang-menu.open { display: block; }
.lang-menu-title { font-size: 12px; color: var(--muted); padding: 4px 16px 6px; text-transform: uppercase; letter-spacing: .5px; }
.lang-menu a { display: block; padding: 10px 16px; color: var(--text); }
.lang-menu a:hover { background: var(--bg-soft); text-decoration: none; }
.lang-menu a.current { font-weight: bold; color: var(--link); }

/* ---------- Kielivalintasivu (kuten wikipedia.org) ---------- */
body:has(.portal) .header, body:has(.portal) footer { display: none; }
.portal { text-align: center; padding: 34px 0 20px; }
.portal .globe { width: 132px; height: 132px; display: block; margin: 0 auto 10px; }
.portal h1 { font-family: var(--serif); font-weight: normal; font-size: 40px; letter-spacing: 1px; margin: 0; border: 0; }
.portal .slogan { font-family: var(--serif); color: var(--muted); font-size: 16px; margin: 2px 0 28px; }
.portal .langs { display: grid; grid-template-columns: 1fr; gap: 10px; max-width: 360px; margin: 0 auto; }
.portal .langs a {
  display: block; border: 1px solid var(--border); border-radius: 2px; padding: 12px 14px; color: var(--text); background: #fff;
}
.portal .langs a:hover { background: var(--bg-soft); text-decoration: none; border-color: var(--link); }
.portal .langs b { display: block; font-size: 19px; color: var(--link); font-weight: 600; }
.portal .langs span { font-family: var(--serif); font-size: 14px; color: var(--muted); }
.portal .small { font-size: 12px; color: var(--muted); margin-top: 30px; font-style: italic; }

/* Kuvat artikkelissa (pikkukuva + kuvateksti) */
.fig { margin: 6px 0 14px; padding: 4px; border: 1px solid var(--border-light); background: var(--bg-soft); }
.fig img { width: 100%; height: auto; display: block; }
.fig figcaption { font-size: 13px; line-height: 1.4; color: var(--muted); padding: 5px 2px 2px; }
@media (min-width: 760px) {
  /* Tietokoneella kuvat tekstin seassa, ettei infoboxin alle jää tyhjää aluetta */
  .fig { float: none; width: 340px; max-width: 100%; margin: 8px 0 16px; }
}
details.section > .body::after { content: ''; display: block; clear: both; }

/* Kemi-artikkelin kohteet */
.kemi-stop { padding: 6px 0 16px; border-bottom: 1px solid var(--border-light); margin-bottom: 10px; }
.kemi-stop:last-child { border-bottom: 0; }
.kemi-stop h3 { font-family: var(--serif); font-weight: normal; font-size: 21px; margin: 2px 0 8px; }
.kemi-kicker { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.kemi-imgs { display: grid; gap: 4px; margin-bottom: 8px; }
.kemi-imgs.n2 { grid-template-columns: 1fr 1fr; }
.kemi-imgs.n4 { grid-template-columns: 1fr 1fr; }
.kemi-imgs img { width: 100%; height: auto; display: block; border: 1px solid var(--border-light); }
.kemi-rate { font-size: 13px; color: var(--muted); background: var(--bg-soft); border-left: 3px solid #c9a227; padding: 5px 9px; }
.kemi-rate .stars { color: #c9a227; letter-spacing: 1px; margin-right: 6px; }
@media (min-width: 760px) { .kemi-imgs.n1 img { max-width: 520px; } }

/* Pidempi nimi mahtuu myös kapeisiin puhelimiin */
.header .brand span { font-size: clamp(17px, 5.6vw, 22px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 380px) {
  .header { gap: 2px; padding: 0 4px; }
  .header .menu, .header .search-btn, .header .lang-btn { width: 36px; padding: 7px; }
  .header .brand { gap: 6px; }
  .header .brand img { width: 26px; height: 26px; }
}

/* Liput */
.flag { display: inline-block; line-height: 0; vertical-align: middle; }
.flag svg { width: 22px; height: 14px; border: 1px solid rgba(0,0,0,.15); border-radius: 2px; }
.lang-menu a { display: flex; align-items: center; gap: 10px; }
.portal .langs a { display: flex; align-items: center; gap: 16px; text-align: left; padding: 12px 16px; }
.portal .langs .flag svg { width: 52px; height: 33px; border-radius: 3px; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.portal .langs .lang-txt { display: block; }
