/* Hemma — familjeapp. Mobil först, ljust och mörkt läge. */

:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efedea;
  --line: #e0ddd7;
  --text: #201d1a;
  --muted: #6f6a63;
  --faint: #a09a91;
  --accent: #2f6fed;
  --accent-soft: #e5edfd;
  --good: #2f9e44;
  --warn: #e8590c;
  --bad: #d6336c;
  --shadow: 0 1px 2px rgba(32, 29, 26, .06), 0 6px 20px rgba(32, 29, 26, .06);
  --radius: 16px;
  --tap: 44px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --nav-h: calc(58px + var(--safe-b));
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17161a;
    --surface: #222126;
    --surface-2: #2c2b31;
    --line: #38363e;
    --text: #f2f0ee;
    --muted: #a29daa;
    --faint: #6f6a78;
    --accent: #7ea6ff;
    --accent-soft: #1e2a44;
    --good: #64c27b;
    --warn: #ff9f5a;
    --bad: #ff7aa8;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ struktur */

#app { min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 19px; font-weight: 700; letter-spacing: -.01em; flex: 1; min-width: 0; }
.topbar .sub { display: block; font-size: 12px; font-weight: 500; color: var(--muted); letter-spacing: 0; }

.icon-btn {
  width: var(--tap); height: var(--tap); flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 12px; background: transparent; font-size: 20px;
}
.icon-btn:active { background: var(--surface-2); }

main { flex: 1; padding: 14px 14px calc(var(--nav-h) + 20px); }
.view { display: none; }
.view.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.nav button {
  border: 0; background: transparent; padding: 7px 2px 9px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 10.5px; font-weight: 600; color: var(--muted); letter-spacing: .01em;
}
.nav button i { font-style: normal; font-size: 21px; line-height: 1; }
.nav button[aria-current='true'] { color: var(--accent); }

/* --------------------------------------------------------------- kort */

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 14px; overflow: hidden;
}
.card > header {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 15px; border-bottom: 1px solid var(--line);
}
.card > header h2 { font-size: 15px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card > header .count { font-size: 12px; font-weight: 600; color: var(--muted); flex: none; }
.card .body { padding: 6px 0; }
.card .body.pad { padding: 14px 15px; }

.section-title {
  margin: 22px 4px 9px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em; color: var(--faint);
}
.section-title:first-child { margin-top: 4px; }

.empty { padding: 22px 16px; text-align: center; color: var(--muted); font-size: 14px; }
.empty .big { font-size: 30px; display: block; margin-bottom: 6px; }

/* ------------------------------------------------------ familjetråden */

.badge {
  flex: none; padding: 2px 9px; border-radius: 999px;
  background: var(--bad); color: #fff; font-size: 11.5px; font-weight: 700;
}

.msg-list { max-height: 340px; overflow-y: auto; padding: 10px 14px; }
.msg { display: flex; gap: 9px; margin-bottom: 12px; align-items: flex-end; }
.msg:last-child { margin-bottom: 2px; }
.msg .avatar { margin-bottom: 14px; }
.msg-body {
  max-width: 78%; padding: 8px 12px;
  border-radius: 15px 15px 15px 4px;
  background: var(--surface-2);
}
.msg.mine { flex-direction: row-reverse; }
.msg.mine .msg-body {
  border-radius: 15px 15px 4px 15px;
  background: var(--accent); color: #fff;
}
.msg-divider {
  display: flex; align-items: center; gap: 10px;
  margin: 4px 0 12px; color: var(--bad);
  font-size: 11.5px; font-weight: 700; letter-spacing: .03em;
}
.msg-divider::before, .msg-divider::after {
  content: ''; flex: 1; height: 1px;
  background: color-mix(in srgb, var(--bad) 40%, transparent);
}
.msg-who { font-size: 12px; font-weight: 700; margin-bottom: 2px; }
.msg-text { font-size: 15px; line-height: 1.35; white-space: pre-wrap; word-break: break-word; }
.msg-time { font-size: 10.5px; margin-top: 3px; opacity: .65; }
.msg.mine .msg-time { text-align: right; }

.msg-compose {
  display: flex; gap: 8px; padding: 11px 13px;
  border-top: 1px solid var(--line);
}
.msg-compose input {
  flex: 1; min-width: 0; min-height: var(--tap); padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--bg);
}
.msg-compose .btn { flex: none; width: var(--tap); padding: 0; border-radius: 50%; font-size: 17px; }

/* Prick på Idag-fliken när något olästs ligger i tråden */
.nav button { position: relative; }
.nav button[data-badge]:not([data-badge=""])::after {
  content: attr(data-badge);
  position: absolute; top: 3px; left: 50%; margin-left: 4px;
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 999px; background: var(--bad); color: #fff;
  font-size: 10.5px; font-weight: 700; line-height: 17px; text-align: center;
}

/* ------------------------------------------------------- fördelningen */

.share-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.share-row:last-child { margin-bottom: 2px; }
.share-main { flex: 1; min-width: 0; }
.share-top { display: flex; align-items: baseline; gap: 8px; margin-bottom: 5px; }
.share-name { font-size: 14.5px; font-weight: 600; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-num { flex: none; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.share-bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.share-bar > i { display: block; height: 100%; border-radius: 999px; transition: width .4s ease; }

/* ------------------------------------------------------------ uppgift */

.task {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 11px 15px; min-height: var(--tap);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
}
.task:last-child { border-bottom: 0; }

.check {
  flex: none; width: 26px; height: 26px; margin-top: 1px;
  border: 2px solid var(--faint); border-radius: 50%;
  background: transparent; padding: 0;
  display: grid; place-items: center;
  font-size: 15px; color: transparent; line-height: 1;
  transition: background .15s, border-color .15s, color .15s;
}
.check[aria-pressed='true'] { background: var(--good); border-color: var(--good); color: #fff; }
.check:active { transform: scale(.9); }

.task .main { flex: 1; min-width: 0; }
.task .title { font-size: 15px; font-weight: 500; word-break: break-word; }
.task.done .title { text-decoration: line-through; color: var(--faint); }
.task .meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin-top: 3px; font-size: 12px; color: var(--muted);
}

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.pill.due-today { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.pill.overdue { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.pill.who { color: #fff; }
.pill.points { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }

.avatar {
  flex: none; display: inline-grid; place-items: center;
  width: 28px; height: 28px; border-radius: 50%;
  font-size: 14px; background: var(--surface-2); border: 2px solid transparent;
}
.avatar.lg { width: 40px; height: 40px; font-size: 20px; }
.avatar.sm { width: 21px; height: 21px; font-size: 11px; }

/* ------------------------------------------------------------ kontroll */

.chips { display: flex; gap: 7px; overflow-x: auto; padding: 2px 4px 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-size: 13px; font-weight: 600; color: var(--muted);
}
.chip[aria-pressed='true'] { background: var(--text); border-color: var(--text); color: var(--bg); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: var(--tap); padding: 0 18px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); font-size: 15px; font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.full { width: 100%; }
.btn:disabled { opacity: .5; }

.quick { display: flex; gap: 8px; margin-bottom: 14px; }
.quick input {
  flex: 1; min-width: 0; min-height: var(--tap); padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
.quick input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + 14px); z-index: 25;
  width: 54px; height: 54px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 27px; line-height: 1;
  box-shadow: 0 6px 20px rgba(47, 111, 237, .4);
}

/* ------------------------------------------------------- framstegsring */

.ring { flex: none; width: 40px; height: 40px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 4; }
.ring .bg { stroke: var(--line); }
.ring .fg { stroke: var(--good); stroke-linecap: round; transition: stroke-dasharray .4s ease; }
.ring-wrap { position: relative; display: grid; place-items: center; }
.ring-wrap span {
  position: absolute; font-size: 11px; font-weight: 700; color: var(--muted);
}

.progress { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--good); transition: width .35s ease; }

/* ------------------------------------------------------------- kalender */

.month-strip { display: flex; gap: 6px; overflow-x: auto; padding: 2px 4px 12px; scrollbar-width: none; }
.month-strip::-webkit-scrollbar { display: none; }
.daycell {
  flex: none; width: 52px; padding: 8px 0 9px; border-radius: 13px;
  border: 1px solid var(--line); background: var(--surface); text-align: center;
}
.daycell .dow { font-size: 10.5px; font-weight: 700; text-transform: uppercase; color: var(--faint); letter-spacing: .05em; }
.daycell .num { font-size: 19px; font-weight: 700; margin-top: 1px; }
.daycell .dots { display: flex; justify-content: center; gap: 3px; height: 6px; margin-top: 3px; }
.daycell .dots i { width: 5px; height: 5px; border-radius: 50%; }
.daycell[aria-pressed='true'] { background: var(--text); border-color: var(--text); color: var(--bg); }
.daycell[aria-pressed='true'] .dow { color: color-mix(in srgb, var(--bg) 70%, transparent); }
.daycell.today .num { color: var(--accent); }
.daycell[aria-pressed='true'].today .num { color: var(--bg); }

.evt { display: flex; gap: 12px; padding: 11px 15px; border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.evt:last-child { border-bottom: 0; }
.evt .time { flex: none; width: 52px; font-size: 13px; font-weight: 700; color: var(--muted); padding-top: 1px; }
.evt .bar { flex: none; width: 3px; border-radius: 2px; background: var(--accent); }
.evt .main { flex: 1; min-width: 0; }

/* ------------------------------------------------------------------ mat */

.meal-row { display: flex; align-items: center; gap: 12px; padding: 11px 15px; border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.meal-row:last-child { border-bottom: 0; }
.meal-row .day { flex: none; width: 62px; }
.meal-row .day b { display: block; font-size: 13px; }
.meal-row .day span { font-size: 11px; color: var(--faint); }
.meal-row .what { flex: 1; min-width: 0; font-size: 15px; }
.meal-row .what.blank { color: var(--faint); font-style: italic; }
.meal-row.today { background: var(--accent-soft); }

/* ------------------------------------------------------------- modal */

dialog.sheet {
  width: min(520px, 100%); max-height: 88vh;
  margin: auto auto 0; padding: 0;
  border: 0; border-radius: 20px 20px 0 0;
  background: var(--surface); color: var(--text);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, .25);
}
@media (min-width: 560px) { dialog.sheet { margin: auto; border-radius: 20px; } }
dialog.sheet::backdrop { background: rgba(0, 0, 0, .45); backdrop-filter: blur(2px); }
dialog.sheet[open] { animation: rise .2s ease; }
@keyframes rise { from { transform: translateY(18px); opacity: 0; } }

.sheet-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { flex: 1; font-size: 16px; font-weight: 700; }
.sheet-body { padding: 16px; overflow-y: auto; max-height: 62vh; }
.sheet-foot { display: flex; gap: 10px; padding: 14px 16px calc(14px + var(--safe-b)); border-top: 1px solid var(--line); }
.sheet-foot .btn { flex: 1; }

.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12.5px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.field input[type='text'], .field input[type='date'], .field input[type='time'],
.field input[type='number'], .field select, .field textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 11px; background: var(--bg);
}
.field textarea { min-height: 76px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field .hint { margin-top: 6px; font-size: 12px; line-height: 1.35; color: var(--muted); }
.field-row { display: flex; gap: 10px; }
.field-row > .field { flex: 1; }

.picker { display: flex; flex-wrap: wrap; gap: 8px; }
.picker button {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg);
  font-size: 13.5px; font-weight: 600; color: var(--muted);
}
.picker button[aria-pressed='true'] { border-color: currentColor; background: var(--surface-2); color: var(--text); }

/* --------------------------------------------------------------- login */

.login { max-width: 420px; margin: 0 auto; padding: 34px 20px calc(40px + var(--safe-b)); }
.login .logo { font-size: 46px; text-align: center; }
.login h1 { text-align: center; font-size: 27px; margin: 10px 0 6px; }
.login p.lead { text-align: center; color: var(--muted); margin: 0 0 26px; }
.login .who { display: grid; gap: 10px; margin-bottom: 20px; }
.login .who button {
  display: flex; align-items: center; gap: 13px;
  padding: 13px 15px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface); text-align: left;
}
.login .who button b { font-size: 16px; }
.login .who button small { display: block; color: var(--muted); font-weight: 500; font-size: 12.5px; }
.login .who button[aria-pressed='true'] { border-color: var(--accent); background: var(--accent-soft); }

.pinbox {
  width: 100%; text-align: center; letter-spacing: .5em; font-size: 26px; font-weight: 700;
  padding: 13px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface);
}

.notice {
  padding: 11px 14px; border-radius: 12px; margin-bottom: 14px; font-size: 14px;
  background: color-mix(in srgb, var(--bad) 13%, transparent); color: var(--bad);
}
.notice.info { background: var(--accent-soft); color: var(--accent); }

/* ------------------------------------------------------------- toast */

#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); z-index: 60;
  transform: translate(-50%, 16px);
  padding: 11px 18px; border-radius: 999px;
  background: var(--text); color: var(--bg);
  font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  display: flex; align-items: center; gap: 12px;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { border: 0; background: transparent; color: var(--accent); font-weight: 700; padding: 0; }

.offline-bar {
  padding: 7px 14px; text-align: center; font-size: 12.5px; font-weight: 600;
  background: var(--warn); color: #fff;
}

/* -------------------------------------------------------- enkelt läge */

body.simple .task { padding: 15px; }
body.simple .task .title { font-size: 17px; }
body.simple .check { width: 32px; height: 32px; font-size: 18px; }
body.simple .nav { grid-template-columns: repeat(3, 1fr); }

/* ------------------------------------------------------------- plugg */

/* Fotovalet ska vara knappar man ser, inte en filväljare man letar efter. */
.photo-choice { display: grid; gap: 10px; }
@media (min-width: 420px) { .photo-choice { grid-template-columns: 1fr 1fr; } }

.photo-btn {
  display: flex; align-items: center; gap: 13px; width: 100%;
  padding: 16px 14px; text-align: left;
  border: 2px dashed color-mix(in srgb, var(--accent) 45%, var(--line));
  border-radius: 14px; background: var(--accent-soft); color: var(--text);
}
.photo-btn.alt {
  border-style: solid;
  border-color: var(--line);
  background: var(--surface);
}
.photo-btn:active { transform: scale(.995); }
.photo-btn .photo-ico { flex: none; font-size: 27px; line-height: 1; }
.photo-btn .photo-txt { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.photo-btn .photo-txt b { font-size: 15.5px; }
.photo-btn .photo-txt small { font-size: 12px; color: var(--muted); }

.photo-preview:empty { display: none; }
.photo-preview { margin-top: 12px; }
.photo-count { font-size: 12.5px; font-weight: 700; color: var(--muted); margin-bottom: 8px; }

.photo-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.photo-strip::-webkit-scrollbar { display: none; }
.photo-thumb { position: relative; flex: none; width: 84px; }
.photo-thumb img {
  width: 84px; height: 108px; object-fit: cover; display: block;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2);
}
.photo-thumb .photo-num {
  position: absolute; left: 5px; bottom: 5px;
  padding: 1px 7px; border-radius: 999px;
  background: rgba(0, 0, 0, .62); color: #fff; font-size: 11px; font-weight: 700;
}
.photo-thumb .photo-drop {
  position: absolute; top: -6px; right: -6px;
  width: 24px; height: 24px; border-radius: 50%; border: 0; padding: 0;
  background: var(--bad); color: #fff; font-size: 12px; line-height: 1;
  display: grid; place-items: center;
}

.pair-row { display: flex; align-items: center; gap: 7px; margin-bottom: 8px; }
.pair-row input { flex: 1; min-width: 0; min-height: 42px; padding: 8px 11px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
/* Ett tomt svar ska synas — det är där appen sa att den inte visste. */
.pair-back.blank {
  border-color: var(--warn);
  background: color-mix(in srgb, var(--warn) 10%, var(--bg));
}
.pair-row .pair-eq { flex: none; color: var(--faint); font-weight: 700; }
.pair-row .icon-btn { flex: none; width: 34px; height: 34px; font-size: 15px; color: var(--faint); }

dialog.drill {
  width: 100%; max-width: none; height: 100%; max-height: none;
  margin: 0; padding: 0; border: 0;
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column;
}
dialog.drill:not([open]) { display: none; }
dialog.drill::backdrop { background: var(--bg); }
/* Raden under rubriken bär framstegen — den måste synas även när den är tom. */
dialog.drill > .progress { height: 5px; background: var(--line); }

.drill-head {
  display: flex; align-items: center; gap: 10px; flex: none;
  padding: max(12px, env(safe-area-inset-top)) 14px 12px;
  border-bottom: 1px solid var(--line);
}
.drill-head h2 { flex: 1; min-width: 0; font-size: 16px; font-weight: 700;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drill-head .count { flex: none; font-size: 13px; font-weight: 700; color: var(--muted); }

.drill-body {
  flex: 1; display: flex; flex-direction: column; justify-content: center;
  padding: 24px 18px; text-align: center; overflow-y: auto;
}
.drill-lang { font-size: 12px; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--faint); margin-bottom: 10px; }
.drill-word { display: flex; align-items: center; justify-content: center; gap: 10px;
  font-size: clamp(28px, 8vw, 40px); font-weight: 700; line-height: 1.15;
  word-break: break-word; margin-bottom: 22px; }
.drill-word .icon-btn { flex: none; font-size: 22px; }

.drill-input {
  width: 100%; max-width: 420px; margin: 0 auto;
  padding: 14px 16px; font-size: 19px; text-align: center;
  border: 2px solid var(--line); border-radius: 14px; background: var(--surface);
}
.drill-input:focus { outline: 0; border-color: var(--accent); }

.drill-choices { display: grid; gap: 10px; max-width: 420px; width: 100%; margin: 0 auto; }
.drill-choice { min-height: 54px; font-size: 17px; }

.drill-answer { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line); }
.drill-answer .drill-word { font-size: clamp(24px, 6.5vw, 34px); margin-bottom: 0; color: var(--good); }

.drill-fb { margin-top: 20px; font-size: 16px; }
.drill-fb.right { color: var(--good); font-weight: 700; font-size: 20px; }
.drill-fb.wrong { color: var(--bad); }
.drill-fb.wrong b { display: block; font-size: 26px; margin-top: 4px; color: var(--text); }
.drill-yours { margin-top: 8px; font-size: 14px; color: var(--muted); }

.drill-foot {
  flex: none; display: flex; gap: 10px;
  padding: 14px 16px calc(14px + var(--safe-b));
  border-top: 1px solid var(--line);
}
.drill-foot .btn { flex: 1; }

.drill-done .drill-score { font-size: 54px; font-weight: 800; line-height: 1; }
.drill-done .drill-score span { font-size: 20px; font-weight: 600; color: var(--muted); }
.drill-done p { color: var(--muted); }

/* --- plugg: plan, matcha, veckoläxor --- */

.plan {
  padding: 11px 13px; border-radius: 12px; margin-bottom: 12px;
  font-size: 13.5px; line-height: 1.45;
  background: var(--surface-2); color: var(--text);
}
.plan.ok { background: color-mix(in srgb, var(--good) 14%, transparent); }
.plan.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); }

.drill-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.drill-actions .btn { flex: 1; min-width: 108px; font-size: 14px; padding: 0 10px; }

.match-body { justify-content: flex-start; padding-top: 16px; }
.match-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px;
  width: 100%; max-width: 460px; margin: 0 auto;
}
.match-tile {
  min-height: 66px; padding: 10px 8px;
  border: 1px solid var(--line); border-radius: 13px;
  background: var(--surface); color: var(--text);
  font-size: 15px; font-weight: 600; line-height: 1.25;
  word-break: break-word;
  transition: background .15s, border-color .15s, opacity .3s;
}
.match-tile.picked { border-color: var(--accent); background: var(--accent-soft); }
.match-tile.miss { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 16%, transparent); }
.match-tile.gone { opacity: 0; pointer-events: none; }

.wk-row { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.wk-row:last-child { border-bottom: 0; }
.wk-fields { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 7px; }
.wk-sub, .wk-top { display: flex; gap: 7px; }
.wk-row input {
  width: 100%; min-width: 0; min-height: 40px; padding: 8px 11px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.wk-row .wk-title { font-weight: 600; }
.wk-file {
  flex: none; min-width: 52px; min-height: 40px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  font-size: 13px; font-weight: 700; color: var(--muted);
}

/* ------------------------------------------------------------- bilagor */

.att-row { display: flex; align-items: center; gap: 9px; padding: 8px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.att-row:last-child { border-bottom: 0; }
.att-row .att-ico { flex: none; font-size: 21px; line-height: 1; }
.att-main {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px;
  padding: 4px 0; border: 0; background: none; text-align: left; color: inherit;
}
.att-main .att-name {
  font-size: 14.5px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.att-main .att-meta { font-size: 12px; color: var(--muted); }
.att-row .icon-btn { flex: none; width: 36px; height: 36px; font-size: 15px; color: var(--faint); }
.att-linked { margin-top: 9px; font-size: 12.5px; font-weight: 600; color: var(--accent); }

.att-pages { display: flex; flex-direction: column; gap: 14px; }
.att-pages figure { margin: 0; }
.att-pages img {
  display: block; width: 100%; height: auto;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
}
.att-pages figcaption { margin-top: 5px; font-size: 12px; color: var(--muted); text-align: center; }

/* Ett pill som går att trycka på — Öva-knappen på en läxa. Lite högre än
   ett vanligt pill, annars blir träffytan för liten på en telefon. */
.pill.act {
  padding: 5px 11px; border: 0; font-family: inherit;
  background: var(--accent-soft); color: var(--accent); cursor: pointer;
}

.week-pick { display: flex; gap: 6px; flex-wrap: wrap; }
.week-pick button {
  flex: 1; min-width: 46px; min-height: 44px; padding: 6px 4px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--bg); color: var(--muted); font-size: 13px; font-weight: 700;
}
.week-pick button[aria-pressed='true'] {
  background: var(--accent); border-color: var(--accent); color: #fff;
}

.routine-time {
  flex: none; width: 46px; padding-top: 1px;
  font-size: 13px; font-weight: 700; color: var(--muted);
}
.routine-templates { display: grid; gap: 8px; }
.routine-templates .btn {
  justify-content: flex-start; text-align: left;
  min-height: 58px; padding: 10px 14px; line-height: 1.3; font-weight: 600;
}
.routine-templates .btn small { font-weight: 500; color: var(--muted); font-size: 12px; }

body.simple .drill-word { font-size: clamp(32px, 10vw, 46px); }
body.simple .drill-choice { min-height: 62px; font-size: 19px; }

/* ------------------------------------------------- Dator och surfplatta */

/* Appen är byggd mobil först. På en bred skärm ska innehållet centreras i en
   läsbar kolumn i stället för att sträckas ut — en syssla på 1500 px blir en
   kryssruta i ena kanten och en poängpill i den andra. Fälten centreras med
   padding i stället för med wrapper-element, så att de fastsatta listerna
   fortfarande spänner över hela bredden och behåller sin bakgrund. */
@media (min-width: 720px) {
  main,
  .topbar,
  .nav,
  .drill-head,
  .drill-foot {
    padding-inline: max(14px, calc((100% - 680px) / 2));
  }
  /* Utanför kolumnen, inte ovanpå kortkanten. */
  .fab { right: max(16px, calc((100% - 680px) / 2 - 66px)); }
  .msg-list { max-height: 420px; }
}

/* Pekvänliga ytor behövs inte med mus — men de får inte krympa så mycket att
   de blir svåra att träffa på en surfplatta, som saknar hover helt. */
@media (min-width: 720px) and (hover: hover) and (pointer: fine) {
  .btn:hover, .chip:hover, .icon-btn:hover, .task:hover { background: var(--surface-2); }
  .btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
  .match-tile:hover { border-color: var(--accent); }
  .nav button:hover { color: var(--text); }
}

/* ------------------------------------------------------- dagens ord */

.wd-grid { display: grid; gap: 7px; justify-content: center; margin: 2px 0 16px; }
.wd-row { display: grid; grid-template-columns: repeat(5, minmax(0, 54px)); gap: 7px; }

.wd-cell {
  aspect-ratio: 1; display: grid; place-items: center;
  font-size: clamp(20px, 6vw, 26px); font-weight: 800; text-transform: uppercase;
  border: 2px solid var(--line); border-radius: 10px; background: var(--surface);
  color: var(--text);
}
/* Färgerna måste hålla även för den som inte skiljer grönt från gult, så varje
   ruta bär också ett tecken i hörnet: ✓ rätt plats, • finns i ordet. */
.wd-cell { position: relative; }
.wd-cell[data-sign]::after {
  content: attr(data-sign); position: absolute; top: 1px; right: 4px;
  font-size: 11px; font-weight: 700; opacity: .85;
}
/* Gult för "finns i ordet, fel plats". --warn är röd-orange i den här paletten
   och läser som *fel* — precis motsatsen till vad rutan betyder. Mörk text på
   gult i stället för vit: gult är för ljust för att bära vit text. */
.wd-cell.hit  { background: var(--good); border-color: var(--good); color: #fff; }
.wd-cell.near { background: #d8a62e; border-color: #d8a62e; color: #201d1a; }
.wd-cell.miss { background: var(--surface-2); border-color: var(--surface-2); color: var(--muted); }
.wd-cell.now  { border-color: var(--accent); }

.wd-keys {
  display: flex; flex-wrap: wrap; gap: 5px; justify-content: center;
  max-width: 320px; margin: 0 auto 16px;
}
.wd-key {
  min-width: 24px; padding: 3px 6px; border-radius: 6px; text-align: center;
  font-size: 13px; font-weight: 700; background: var(--surface-2); color: var(--muted);
}
.wd-key.hit  { background: var(--good); color: #fff; }
.wd-key.near { background: #d8a62e; color: #201d1a; }
.wd-key.miss { opacity: .3; }

.wd-input {
  width: 100%; max-width: 260px; margin: 0 auto; display: block;
  text-align: center; letter-spacing: .3em; text-transform: uppercase;
  font-size: 22px; font-weight: 700; padding: 12px 10px;
  border: 2px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text);
}
.wd-input:focus { outline: 0; border-color: var(--accent); }

.wd-streak { font-size: 15px; font-weight: 700; color: var(--warn); }
.wd-word { font-size: 26px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.wd-family { display: grid; gap: 6px; margin-top: 4px; }
.wd-family div { display: flex; gap: 8px; align-items: baseline; font-size: 15px; }
.wd-family div span:first-child { flex: 1; min-width: 0; }
.wd-family .muted { color: var(--muted); }

@media (prefers-color-scheme: dark) {
  .wd-cell.near { background: #c2912a; border-color: #c2912a; }
  .wd-key.near  { background: #c2912a; }
}

/* ------------------------------------------------------------- tango */

.pz-games { display: grid; gap: 8px; }
.pz-games .btn { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pz-games .pz-state { font-weight: 600; opacity: .75; font-size: 14px; }

.tg-wrap { width: 100%; max-width: 330px; margin: 0 auto 14px; }

/* Rutorna och tecknen ligger i samma rutnät: sex breda spår för rutor med
   smala spår emellan för = och ×. Att lägga tecknen absolut ovanpå hade krävt
   uträknade koordinater som spricker så fort rutstorleken ändras. */
.tg-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr) 17px) minmax(0, 1fr);
  grid-template-rows: repeat(5, auto 17px) auto;
}

.tg-cell {
  aspect-ratio: 1; display: grid; place-items: center;
  font-size: clamp(17px, 5.4vw, 25px); line-height: 1;
  border: 2px solid var(--line); border-radius: 9px;
  background: var(--surface); color: var(--text);
  -webkit-tap-highlight-color: transparent; cursor: pointer;
  padding: 0;
}
.tg-cell.given { background: var(--surface-2); border-color: var(--surface-2); cursor: default; }
.tg-cell.bad { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--surface)); }
.tg-cell:disabled { cursor: default; }

.tg-sign {
  display: grid; place-items: center;
  font-size: 12px; font-weight: 800; color: var(--muted);
}
.tg-sign.eq { color: var(--accent); }
.tg-sign.ne { color: var(--bad); }

.tg-rules { font-size: 12.5px; color: var(--muted); text-align: center; margin: 0 auto 12px; max-width: 330px; }
.tg-time { font-variant-numeric: tabular-nums; }
.tg-note { margin-top: 12px; font-size: 15px; }
.tg-note.bad { color: var(--bad); }

/* ---------------------------------------------------------- dagsrutiner */
/* Rutinkorten återanvänder .card och .task så att de ser inbyggda ut.
   Det som tillkommer är tidsraden, varför-texten och varaktighetsmätaren. */

.card.routine > header { gap: 10px; }
.rhead { flex: 1; min-width: 0; }
.rhead h2 { font-size: 15px; font-weight: 700; margin: 0; }
.rhead-sub {
  margin-top: 2px;
  font-size: 12px; font-weight: 600; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.card.routine.all-done > header {
  background: color-mix(in srgb, var(--good) 10%, transparent);
}

.rintro {
  padding: 11px 15px 3px;
  font-size: 13.5px; color: var(--muted);
}

.task.rstep { align-items: flex-start; }
.task.rstep .check { margin-top: 1px; }

.rwhy {
  margin-top: 3px;
  font-size: 13px; line-height: 1.45; color: var(--muted);
  max-width: 46ch;
}
.task.rstep.done .rwhy { color: var(--faint); }

/* Hur lång stunden är, i förhållande till rutinens längsta steg. Fem minuter
   ska se ut som fem minuter — det är hela poängen med mätaren. */
.rbar {
  margin-top: 7px; width: 92px; height: 4px;
  border-radius: 4px; background: var(--surface-2); overflow: hidden;
}
.rbar span {
  display: block; height: 100%; border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 55%, transparent);
}
.task.rstep.done .rbar span { background: color-mix(in srgb, var(--good) 60%, transparent); }

.pill.now {
  background: var(--accent); color: #fff; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase;
}

.rend {
  padding: 11px 15px 13px; margin-top: 2px;
  border-top: 1px solid var(--line);
  font-size: 13.5px; color: var(--muted);
}
.rend b { color: var(--text); font-variant-numeric: tabular-nums; }

.rcheer {
  margin: 0 15px 14px; padding: 11px 13px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--good) 13%, transparent);
  color: var(--good); font-size: 14px; font-weight: 600; text-align: center;
}
