/* Trees — "For the First Time": haalistunut 70-luvun filmikuva, auringonlasku järvellä.
 * Puuteri, pölyinen ruusu, luumu, terrakotta. Mobiili ensin (360 px).
 * Kontrastit (WCAG): teksti/tausta ≥ 5,4:1 molemmissa teemoissa, CTA valkoisella ≥ 5,5:1. */

/* Fontit omalta palvelimelta (ei Googlelle jäsenten IP-osoitteita). OFL 1.1, ks. fonts/OFL-*.txt.
 * Figtree on muuttuva fontti: yksi tiedosto kattaa painot 400–700. */
@font-face {
  font-family: "Figtree";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../fonts/figtree-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Figtree";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../fonts/figtree-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face { /* Lato Bold otsikoihin (Teemu 1.10.: Italiana liian ohut). Latin kattaa ä, ö, å. */
  font-family: "Lato";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/lato-700-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  /* Vaalea: haalistunut paperi/puuteri, luumuinen teksti */
  --bg: #f1e8e3;
  --surface: #faf5f1;
  --ink: #4a2328;
  --muted: #7a5352;
  --line: #e0cfc8;
  --accent: #6a3535;        /* siluetin luumu */
  --accent-ink: #ffffff;
  --cta: #863b34;           /* paidan terrakotta */
  --cta-ink: #ffffff;
  --powder: #e9dcda;        /* logon täyte */
  --night: #5a2c2e;         /* yläpalkki, tilarivi */
  --sun: #f2c9a1;           /* laskevan auringon hehku: "kaikki käyvät" */
  --sun-ink: #4a2328;
  --all-ring: var(--accent);
  --danger: #a3352b;
  --own-bg: var(--accent);  /* JS asettaa jäsenen oman värin */
  --own-ink: #ffffff;
  --radius: 12px;
  --font-display: "Lato", "Helvetica Neue", Arial, sans-serif;
  --font-body: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --tap: 44px;
  --sunset: linear-gradient(90deg, #b7bfbf 0%, #b4aba0 35%, #b79b8d 60%, #8a5853 85%, #6a3535 100%);
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Tumma: syvä luumu/ruskea yö, puuterinen teksti */
    --bg: #24151a;
    --surface: #321e23;
    --ink: #f0e4df;
    --muted: #c7aba6;
    --line: #4a3034;
    --accent: #e9b9a7;
    --accent-ink: #24151a;
    --cta: #a64f38;
    --night: #3a2024;
    --all-ring: var(--powder);
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
}

button, input, textarea { font: inherit; color: inherit; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

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

/* ---------- Napit ---------- */

.btn {
  min-height: var(--tap);
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.btn-primary { background: var(--cta); color: var(--cta-ink); }
.btn-primary:active { transform: translateY(1px); }
.btn-ghost { background: transparent; color: inherit; border: 1.5px solid currentColor; opacity: .85; }
.btn-small { padding: 0 12px; font-size: .875rem; }

/* ---------- Logo (PNG-maski: väri = currentColor) ---------- */

.logo-mark {
  display: inline-block;
  aspect-ratio: 508 / 143;
  background-color: currentColor;
  -webkit-mask: url("../img/trees-logo.png") center / contain no-repeat;
  mask: url("../img/trees-logo.png") center / contain no-repeat;
  flex: none;
}
.logo-bar { height: 26px; color: var(--powder); }
.logo-xl { width: min(62vw, 280px); color: var(--powder); }

/* ---------- Kirjautuminen ---------- */

.page-login {
  min-height: 100vh;
  min-height: 100dvh;
  background: #2a171b;
  color: var(--powder);
}
.login {
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  padding: 0 0 40px;
}
.login-cover {
  position: relative;
  aspect-ratio: 4 / 3;
  max-height: 46vh;
  width: 100%;
  overflow: hidden;
  background: #8a5853;
}
.login-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 100%; /* kannen oma tekstilogo rajautuu pois ylhäältä */
}
.login-cover::before, .login-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.login-cover::before { /* filmirae */
  background-image: var(--grain);
  mix-blend-mode: overlay;
  opacity: .5;
}
.login-cover::after { /* vinjetti + liuku taustaan */
  background:
    radial-gradient(ellipse at 50% 35%, transparent 45%, rgba(36, 21, 26, .55) 100%),
    linear-gradient(to bottom, transparent 45%, #2a171b 100%);
}
.login-brand {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  z-index: 1;
  text-align: center;
}
.login-title { margin: 0; line-height: 0; }
.tagline {
  margin: 6px 0 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: .12em; /* pienillä kirjaimilla, kuten Teemu kirjoitti */
  color: var(--powder);
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 16px 16px 0;
  padding: 20px 18px;
  border-radius: 18px;
  background: rgba(233, 220, 218, .06);
  border: 1px solid rgba(233, 220, 218, .18);
}
.login-form label { font-weight: 600; font-size: .95rem; margin-top: 8px; }
.login-form input {
  min-height: 48px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1.5px solid rgba(233, 220, 218, .3);
  background: rgba(0, 0, 0, .25);
  color: #f6eeeb;
  font-size: 16px; /* ei zoomia iOS:ssä */
}
.login-form input:focus { border-color: var(--sun); outline: none; }
.login-form .btn { margin-top: 18px; min-height: 50px; font-size: 1.05rem; background: #a64f38; }
.form-error {
  margin: 0 0 4px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(163, 53, 43, .35);
  border: 1px solid rgba(240, 150, 130, .5);
}
@media (min-width: 520px) {
  .login { padding-top: 32px; }
  .login-cover { border-radius: 18px; }
  .login-form { margin: 16px 0 0; }
}

/* ---------- Yläpalkki ---------- */

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: linear-gradient(180deg, #6a3535, var(--night));
  color: var(--powder);
}
.topbar::after { /* taivas → horisontti → vesi → metsä */
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -4px;
  height: 4px;
  background: var(--sunset);
}
.brand { display: flex; align-items: center; }
.topbar-user { display: flex; align-items: center; gap: 8px; margin: 0; min-width: 0; }
.me-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Sisältö ---------- */

.app { max-width: 640px; margin: 0 auto; padding: 24px 12px 96px; }

.intro-title {
  margin: 4px 0 6px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 2.4rem;
  line-height: 1.05;
  letter-spacing: .02em;
  color: var(--accent);
}
.intro-text { margin: 0 0 16px; font-size: 1.05rem; }

/* ---------- Yhteenveto ---------- */

.summary {
  padding: 12px 12px 10px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
}
.summary-title {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
}
.summary-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.summary-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: .95rem;
}
.summary-list li.is-empty { border-style: dashed; }
.summary-count { font-weight: 700; }
.summary-list li.is-empty .summary-count { font-weight: 400; color: var(--muted); font-style: italic; }
.summary-all { margin: 10px 0 0; font-size: .95rem; }
.summary-all strong { color: var(--accent); }

/* Nimikirjainpallo */
.dot {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--c, #888);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 0 0 1.5px var(--surface);
  flex: none;
}
.summary-list .dot { width: 26px; height: 26px; font-size: 12px; box-shadow: none; }

/* ---------- Kalenteri ---------- */

.month { margin-top: 22px; }

.month-head {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: 0 -12px 6px;
  padding: 8px 12px 6px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.month-head-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.month-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.5rem;
  line-height: 1.1;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
}
.month-toggle {
  min-height: var(--tap);
  padding: 0 14px;
  border-radius: 999px;
  border: 1.5px solid var(--accent);
  background: transparent;
  color: var(--ink);
  font-weight: 700;
  font-size: .9rem;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}
.month-toggle[aria-pressed="true"] { border-color: var(--line); color: var(--muted); font-weight: 600; }

.weekday-row, .week {
  display: grid;
  /* päivät + kommenttisarake */
  grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr)) var(--tap);
  gap: 6px;
}
.weekday-row { margin-top: 6px; }
.weekday-row span {
  text-align: center;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.week { margin-bottom: 6px; }

.day {
  position: relative;
  min-height: 64px;
  min-width: 0;
  padding: 5px;
  border-radius: var(--radius);
  border: 1.5px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .12s, border-color .12s, transform .08s;
}
.day:active { transform: scale(.97); }
.day-wd { display: block; font-size: .72rem; color: var(--muted); line-height: 1; }
.day-date { display: block; font-weight: 700; font-size: 1.05rem; line-height: 1.15; }
.dots { display: flex; flex-wrap: wrap; gap: 2px; min-height: 16px; }

/* Oma valinta: täyttö jäsenen omalla värillä */
.day.is-own { background: var(--own-bg); border-color: var(--own-bg); color: var(--own-ink); }
.day.is-own .day-wd { color: inherit; opacity: .85; }
.day.is-own .dot { box-shadow: 0 0 0 1.5px var(--own-bg); }

/* Kaikki käyvät: kaksoiskehys (taustan värinen rako + luumu/puuteri rengas) + aurinko-★.
   Erottuu omasta täytöstä, koska kehys on solun ulkopuolella. */
.day.is-all { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4.5px var(--all-ring); }
.all-badge {
  position: absolute;
  top: -8px;
  right: -6px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--sun);
  color: var(--sun-ink);
  border: 2px solid var(--bg);
  font-size: 12px;
  line-height: 1;
}

.day-empty { min-height: 64px; }

/* ---------- Kommentit ---------- */

.week-comments {
  position: relative;
  min-height: 64px;
  width: var(--tap);
  padding: 0;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
}
.week-comments .bubble { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.week-comments.has-comments { border-style: solid; border-color: var(--accent); color: var(--accent); }
.week-comments.has-comments .bubble { fill: color-mix(in srgb, var(--accent) 16%, transparent); }
.week-comments.is-open { background: var(--surface); border-color: var(--cta); color: var(--cta); }
@media (prefers-color-scheme: dark) { .week-comments.is-open { border-color: var(--accent); color: var(--accent); } }
.comment-count {
  position: absolute;
  top: 6px;
  right: 3px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.thread {
  margin: -2px 0 10px;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1.5px solid var(--accent);
}
.thread-empty { margin: 0 0 8px; color: var(--muted); font-size: .95rem; }
.thread-list { list-style: none; margin: 0 0 8px; padding: 0; }
.comment { padding: 8px 0; border-bottom: 1px solid var(--line); }
.comment:first-child { padding-top: 0; }
.comment-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.comment-head .dot { width: 20px; height: 20px; font-size: 10px; box-shadow: none; }
.comment-when { color: var(--muted); font-size: .85rem; }
.comment-body {
  margin: 4px 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.comment-delete {
  min-height: var(--tap);
  margin-top: 2px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: .875rem;
  text-decoration: underline;
  cursor: pointer;
}
.comment-delete.is-armed { color: var(--danger); font-weight: 700; }
@media (prefers-color-scheme: dark) { .comment-delete.is-armed { color: #f0a493; } }
.thread-form { display: flex; gap: 8px; align-items: flex-end; }
.thread-input {
  flex: 1;
  min-width: 0;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  background: var(--bg);
  font-size: 16px; /* ei zoomia iOS:ssä */
  resize: vertical;
}
.thread-input:focus { border-color: var(--accent); outline: none; }
.thread-send { flex: none; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin: 22px 0 0;
  font-size: .85rem;
  color: var(--muted);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 700;
}
.legend-own { background: var(--own-bg); }
.legend-other { border-radius: 50%; background: #4f7186; color: #fff; }
.legend-all { border-radius: 50%; background: var(--sun); color: var(--sun-ink); box-shadow: 0 0 0 1.5px var(--all-ring); }

/* ---------- Sivunavigaatio (oma rivi yläpalkin alla: mahtuu 360 px) ---------- */

.topnav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 4px; /* auringonlaskuraita yläpalkin alla */
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topnav-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  font-weight: 700;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 3px solid transparent;
}
.topnav-link[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Keikat ---------- */

.flash {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1.5px solid var(--accent);
  font-weight: 600;
}
.flash.is-error { border-color: var(--danger); color: var(--danger); }
@media (prefers-color-scheme: dark) { .flash.is-error { color: #f0a493; border-color: #f0a493; } }

.section-title {
  margin: 22px 0 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
}
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }

.gig-add > summary { display: inline-flex; align-items: center; }
.gig-add[open] > summary { margin-bottom: 10px; }

.gig-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.gig {
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-left: 5px solid var(--accent);
}
.gig.is-tentative { border: 2px dashed var(--muted); border-left-width: 5px; background: transparent; }
.gig-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 10px; }
.gig-date {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.6rem;
  line-height: 1.1;
  color: var(--accent);
}
.gig-badge {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: .8rem;
  font-weight: 700;
}
.gig.is-tentative .gig-badge { background: transparent; color: var(--ink); border: 1.5px dashed var(--ink); }
.gig-venue { margin: 6px 0 0; font-weight: 700; font-size: 1.15rem; overflow-wrap: anywhere; }
.gig-city { margin: 0; color: var(--muted); }
.gig-note { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.gig-panel { margin-top: 8px; border-top: 1px solid var(--line); }
.gig-panel > summary {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  font-weight: 700;
  color: var(--accent);
}
.gig-panel > summary::before { content: "▸"; margin-right: 6px; }
.gig-panel[open] > summary::before { content: "▾"; }
.gig-panel .thread { margin: 0 0 6px; }

.gigs-past { margin-top: 10px; }
.gigs-past > summary { display: flex; align-items: center; min-height: var(--tap); margin: 12px 0; }
.gigs-past > summary::before { content: "▸"; margin-right: 6px; }
.gigs-past[open] > summary::before { content: "▾"; }

.gig-form { display: grid; gap: 10px; margin: 6px 0 10px; }
.field { display: grid; gap: 4px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field label, .field legend { font-weight: 600; font-size: .95rem; padding: 0; }
.field input:not([type="radio"]), .field textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 8px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  background: var(--bg);
  font-size: 16px; /* ei zoomia iOS:ssä */
}
.field input:focus, .field textarea:focus { border-color: var(--accent); outline: none; }
.choice { display: flex; align-items: center; gap: 8px; min-height: var(--tap); font-weight: 400; }
.choice input { width: 20px; height: 20px; accent-color: var(--accent); }
.gig-form > .btn { justify-self: start; }

.confirm { margin-top: 2px; }
.confirm > summary {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  color: var(--muted);
  font-size: .875rem;
  text-decoration: underline;
}
.confirm[open] > summary { color: var(--danger); font-weight: 700; }
.btn-danger { background: var(--danger); color: #fff; }
.dot-svg { flex: none; }

/* ---------- Tilarivi ---------- */

.status {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 20;
  max-width: calc(100% - 24px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--night);
  color: var(--powder);
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
  transform: translate(-50%, 140%);
  opacity: 0;
  transition: transform .2s, opacity .2s;
  pointer-events: none;
}
.status.is-visible { transform: translate(-50%, 0); opacity: 1; }
.status.is-error { background: var(--danger); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media (min-width: 520px) {
  .day { min-height: 76px; padding: 8px; }
  .day-empty { min-height: 76px; }
  .dot { width: 20px; height: 20px; font-size: 11px; }
  .dots { gap: 3px; min-height: 20px; }
}
