:root {
  --bg: #f7f1ea;
  --card: #ffffff;
  --ink: #2a1a10;
  --muted: #7a6656;
  --brand: #3b2416;
  --accent: #c8792b;
  --line: #e6dbcf;
  --radius: 16px;
  --coffee: #6b3e1f;
  --paper: #fffaf2;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1a120c; --card: #261a12; --ink: #f3e9df; --muted: #b29d8a; --line: #3a2a1e; --coffee: #c8792b; --paper: #e9dccd; }
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); }
header { background: var(--brand); padding: calc(env(safe-area-inset-top) + 14px) 20px 14px; display: flex; justify-content: space-between; align-items: center; }
.account { color: #fff; text-decoration: none; font-weight: 600; font-size: .95rem; opacity: .9; }
.logo { color: #fff; font-weight: 800; font-size: 1.4rem; text-decoration: none; letter-spacing: .5px; }
main { max-width: 520px; margin: 0 auto; padding: 20px 16px 60px; }
h1 { font-size: 1.5rem; margin: 4px 0 16px; }
h2 { font-size: 1.1rem; margin: 24px 0 10px; color: var(--muted); font-weight: 600; }
p { line-height: 1.5; }
.muted { color: var(--muted); font-size: .9rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.card a.title { color: var(--ink); text-decoration: none; font-weight: 700; font-size: 1.1rem; display: block; }
a.cardlink { display: block; color: var(--ink); text-decoration: none; }
a.cardlink .title { font-weight: 700; font-size: 1.1rem; }
a.cardlink .title::after { content: " ›"; color: var(--accent); }
a.cardlink:hover, a.cardlink:active { border-color: var(--accent); }
.card .badge + .status-big { margin-top: 8px; }
.status-row { display: flex; align-items: center; gap: 10px; }
.card .status-row a.title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-row .mins { flex: none; min-width: 4.2em; text-align: right; color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; }
.status-icon { flex: none; color: var(--ink); }
.status-icon.faded { opacity: .35; }
.top-list { list-style: none; padding: 4px 16px; margin: 0 0 12px; }
.top-list li { display: flex; gap: 10px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--line); }
.top-list li:last-child { border-bottom: 0; }
.top-list .rank { flex: none; width: 2em; color: var(--muted); font-variant-numeric: tabular-nums; }
.top-list .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.top-list .brews { flex: none; color: var(--muted); font-size: .9rem; }
.top-list li:nth-child(-n+3) .rank { color: var(--accent); font-weight: 800; }
.top-list .you { color: var(--muted); font-weight: 400; }
.swipe { position: relative; margin-bottom: 12px; border-radius: var(--radius); }
.swipe-actions { position: absolute; inset: 0; border-radius: var(--radius); overflow: hidden; display: none; }
.swipe.dir-left .swipe-actions, .swipe.dir-right .swipe-actions { display: flex; }
.swipe-actions .act { flex: 1; display: flex; align-items: center; padding: 0 22px; color: #fff; font-weight: 800; font-size: 1.05rem; opacity: .7; transition: opacity .15s; }
.swipe-actions .act { position: relative; }
.swipe-actions .act > * { position: relative; }
/* Pitoaika: tumma täyttö kasvaa rajan ylittyessä, toiminto laukeaa kun täynnä */
.swipe-actions .act::before { content: ""; position: absolute; inset: 0; background: rgba(0,0,0,.22);
  transform: scaleX(0); transform-origin: left; }
.swipe.dir-right .act-wish::before { transform-origin: left; }
.swipe.dir-left .act-brew::before { transform-origin: right; }
.swipe.armed .swipe-actions .act::before { transform: scaleX(1); transition: transform .6s linear; }
.swipe.held .swipe-actions .act { opacity: 1; }
.act-wish { background: var(--accent); justify-content: flex-start; }
.act-brew { background: #2f7d43; justify-content: flex-end; }
.swipe.dir-right .act-brew, .swipe.dir-left .act-wish { display: none; }
.swipe-card { margin: 0; position: relative; touch-action: pan-y; user-select: none; -webkit-user-select: none;
  transition: transform .22s ease; will-change: transform; }
.swipe-card.dragging { transition: none; }
.intro { border-color: var(--accent); }
.intro h2 { margin: 0 0 6px; color: var(--ink); }
.intro p { margin: 0 0 12px; }
.guide-link { text-align: center; font-size: .9rem; margin: 18px 0 0; }
.guide-link a { color: var(--muted); }
.guide-step { display: flex; gap: 14px; align-items: flex-start; }
.guide-step h2 { margin: 2px 0 6px; color: var(--ink); font-size: 1.05rem; }
.guide-step p { margin: 0 0 10px; }
.step-no { flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800; }
.swipe-hint { color: var(--muted); font-size: .8rem; text-align: center; margin: 4px 0 0; }
.status-meta { justify-content: flex-start; margin: 6px 0 0; }
.row { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

.status-big { font-size: 1.6rem; font-weight: 800; margin: 6px 0 2px; display: flex; align-items: center; gap: 12px; line-height: 1.2; }
.status-line { display: flex; align-items: center; gap: 8px; }
.icon-big { width: 72px; height: 72px; flex: none; }
.icon-small { width: 32px; height: 32px; flex: none; }
.status-icon.icon-btn { width: 56px; height: 56px; display: block; margin: 0 auto 6px; }
/* Kuvakkeissa on valkoinen/vaalea lasi -> pieni vaalea tausta pitää ne luettavina myös tummassa teemassa */
@media (prefers-color-scheme: dark) { .status-icon { background: #f3e9df; border-radius: 14px; padding: 4px; } }
.wishes { display: inline-block; background: var(--accent); color: #fff; border-radius: 999px; padding: 3px 10px; font-size: .85rem; font-weight: 700; }

button, .btn {
  font: inherit; border: 0; border-radius: 12px; padding: 12px 16px; cursor: pointer;
  background: var(--brand); color: #fff; font-weight: 600; text-decoration: none; display: inline-block; text-align: center;
}
@media (prefers-color-scheme: dark) { button, .btn { background: var(--accent); } }
button.secondary { background: transparent; color: var(--ink); border: 1px solid var(--line); }
button.wish { background: var(--accent); width: 100%; font-size: 1.1rem; padding: 14px; }
button:disabled { opacity: .5; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid button { background: var(--card); color: var(--ink); border: 2px solid var(--line); padding: 16px 8px; font-size: 1rem; }
.grid button.active { border-color: var(--accent); }

input[type=text], input[type=number], input[type=password], select {
  font: inherit; width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); margin: 6px 0 12px;
}
.qr { background: #fff; border-radius: var(--radius); padding: 12px; text-align: center; }
.qr img { width: 100%; max-width: 280px; }
.qr .name { color: #000; font-weight: 800; font-size: 1.2rem; margin-top: 6px; }

.tabs { display: flex; gap: 8px; margin-bottom: 10px; }
.tabs button { flex: 1; background: transparent; color: var(--ink); border: 1px solid var(--line); }
.tabs button.active { background: var(--brand); color: #fff; border-color: var(--brand); }
@media (prefers-color-scheme: dark) { .tabs button.active { background: var(--accent); border-color: var(--accent); } }
.badge { display: inline-block; font-size: .78rem; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  background: var(--line); color: var(--ink); text-decoration: none; }
.invite { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 2.2rem; font-weight: 800; letter-spacing: 3px; margin: 6px 0 12px; }
.code-input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.4rem !important; letter-spacing: 3px; text-transform: uppercase; text-align: center; }
label { display: block; font-size: .9rem; font-weight: 600; }
label.check { display: flex; gap: 10px; align-items: center; font-weight: 500; margin: 4px 0 14px; }
label.check input { width: 22px; height: 22px; }
.line { padding: 10px 0; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: 0; }
button.small { padding: 6px 10px; font-size: .85rem; }
details summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: 10px; }
details.danger summary { color: #b3261e; }
button.danger { background: #b3261e; color: #fff; }
form.card button[type=submit], details form button[type=submit] { width: 100%; }
.hint { background: #fff4e0; color: #5a3a10; border-radius: 12px; padding: 12px; font-size: .9rem; margin-bottom: 12px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--brand); color: #fff;
  padding: 12px 18px; border-radius: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 90vw; }
.hidden { display: none !important; }
header { position: relative; }
.header-right { display: flex; align-items: center; gap: 14px; }
button.bell { background: transparent; padding: 4px; border-radius: 10px; line-height: 0; }
button.bell img { width: 24px; height: 24px; display: block; }
button.bell.muted img { opacity: .75; }
.mute-menu { position: absolute; right: 12px; top: calc(100% + 6px); z-index: 20; width: min(300px, calc(100vw - 24px));
  background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0,0,0,.25); padding: 14px; }
.mute-menu .state { font-weight: 600; margin: 0 0 10px; }
.mute-menu .options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mute-menu .options button { padding: 10px 8px; font-size: .9rem; }
.mute-menu .small-print { color: var(--muted); font-size: .8rem; margin: 10px 0 0; line-height: 1.4; }
.mute-menu button.unmute { width: 100%; margin-bottom: 10px; }
.lang-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
footer button.lang { background: transparent; color: var(--muted); border: 1px solid var(--line); padding: 4px 10px; font-size: .8rem; border-radius: 999px; font-weight: 500; }
footer button.lang.active { color: var(--ink); border-color: var(--accent); }
.version { margin-left: auto; }
.update-banner { position: sticky; top: 0; z-index: 10; display: flex; gap: 12px; align-items: center; justify-content: space-between;
  background: var(--accent); color: #fff; padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; }
.update-banner button { background: #fff; color: var(--brand); flex: none; }
.update-banner .small-print { font-size: .8rem; opacity: .9; margin-top: 2px; }
footer { max-width: 520px; margin: 0 auto; padding: 0 16px calc(env(safe-area-inset-bottom) + 32px); color: var(--muted); font-size: .8rem; line-height: 1.5; border-top: 1px solid var(--line); }
footer p { margin: 12px 0 0; }

@media (prefers-color-scheme: dark) {
  /* Tummassa tilassa ääriviivanapit hukkuvat taustaan -> oranssi reunus */
  button.secondary, .tabs button, a.cardlink { border-color: var(--accent); }
  .grid button { border-color: var(--muted); }
  .grid button.active { border-color: var(--accent); }
  input[type=text], input[type=number], input[type=password], select { border-color: var(--muted); }
}

@media print {
  header, footer, .no-print, .toast { display: none !important; }
  body, main { background: #fff; }
  .qr { border: 2px dashed #999; }
}

/* ---------- pannun tila korteissa ---------- */

textarea { font: inherit; width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); margin: 6px 0 12px; resize: vertical; box-sizing: border-box; }

/* Kahvia tulossa: kiertävä liukuvärireuna (reuna = tausta border-boxissa, sisältö padding-boxissa) */
@property --brew-angle { syntax: "<angle>"; initial-value: 0deg; inherits: false; }
.card.brewing {
  position: relative; isolation: isolate; overflow: hidden;
  border: 2px solid transparent;
  background:
    linear-gradient(var(--card), var(--card)) padding-box,
    conic-gradient(from var(--brew-angle), var(--accent), #f6d08b, var(--coffee), #f6d08b, var(--accent)) border-box;
  animation: brew-spin 3s linear infinite;
}
@keyframes brew-spin { to { --brew-angle: 360deg; } }

/* Kuplat: kortin sisällön takana (z-index -1 + isolation) */
.bubbles { position: absolute; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
.bubbles .b {
  position: absolute; bottom: -24px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,.9), rgba(200,121,43,.35) 60%, rgba(200,121,43,.15));
  border: 1px solid rgba(200,121,43,.35);
  animation: bubble-rise linear infinite; opacity: 0;
}
.bubbles .b1 { left: 6%;  width: 10px; height: 10px; animation-duration: 5.5s; animation-delay: 0s; }
.bubbles .b2 { left: 18%; width: 6px;  height: 6px;  animation-duration: 4.2s; animation-delay: 1.3s; }
.bubbles .b3 { left: 31%; width: 14px; height: 14px; animation-duration: 6.4s; animation-delay: .6s; }
.bubbles .b4 { left: 47%; width: 8px;  height: 8px;  animation-duration: 4.8s; animation-delay: 2.1s; }
.bubbles .b5 { left: 60%; width: 12px; height: 12px; animation-duration: 5.9s; animation-delay: 3.0s; }
.bubbles .b6 { left: 72%; width: 7px;  height: 7px;  animation-duration: 4.5s; animation-delay: .9s; }
.bubbles .b7 { left: 84%; width: 11px; height: 11px; animation-duration: 6.1s; animation-delay: 2.6s; }
.bubbles .b8 { left: 93%; width: 6px;  height: 6px;  animation-duration: 3.9s; animation-delay: 1.8s; }
@keyframes bubble-rise {
  0%   { transform: translate(0, 0) scale(.6); opacity: 0; }
  12%  { opacity: .9; }
  50%  { transform: translate(6px, -90px) scale(1); }
  85%  { opacity: .6; }
  100% { transform: translate(-4px, -190px) scale(1.1); opacity: 0; }
}

/* Edistyminen */
.brew-progress { margin-top: 10px; }
.brew-bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.brew-fill { display: block; height: 100%; width: 0; border-radius: 999px;
  background: linear-gradient(90deg, var(--coffee), var(--accent)); transition: width 1s linear; }
.brew-info { display: flex; justify-content: space-between; gap: 10px; margin-top: 6px; font-size: .88rem; }
.brew-pct { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--ink); }
.brew-eta { color: var(--muted); }

/* Kahvia on: kultainen reuna, tuore pannu hehkuu */
.card.ready { border: 2px solid #d9a521; }
.card.ready.fresh { border-color: #f2c230; box-shadow: 0 0 0 3px rgba(242,194,48,.25), 0 0 18px rgba(242,194,48,.45); }
@media (prefers-color-scheme: dark) {
  .card.ready { border-color: #e0b33a; }
  .card.ready.fresh { border-color: #ffd54a; box-shadow: 0 0 0 3px rgba(255,213,74,.2), 0 0 22px rgba(255,213,74,.35); }
}

@media (prefers-reduced-motion: reduce) {
  .card.brewing { animation: none; }
  .bubbles { display: none; }
  .brew-fill { transition: none; }
}

/* Vanhentunut kahvi: aika punaisena pääkallon kanssa */
.stale { color: #d32f2f !important; font-weight: 700; }
.skull { width: 1em; height: 1em; vertical-align: -0.15em; margin-right: 3px; }
@media (prefers-color-scheme: dark) { .stale { color: #ff6b6b !important; } }
