/* ===========================================================================
   Minnesmästaren — stilmall
   En lugn, fokuserad palett (indigo/violett) med kortbaserad layout.
   =========================================================================== */

:root {
  --primary: #5b54e6;
  --primary-dark: #463fc9;
  --primary-soft: #ecebfd;
  --accent: #f59e0b;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --danger: #e23b4e;
  --danger-soft: #fde7ea;

  --bg: #f5f6fb;
  --surface: #ffffff;
  --surface-2: #f8f9fe;
  --border: #e6e8f0;
  --text: #1d2233;
  --muted: #6b7280;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 23, 40, 0.04), 0 8px 24px rgba(20, 23, 40, 0.06);
  --shadow-lg: 0 12px 40px rgba(43, 38, 110, 0.16);
  --ring: 0 0 0 3px rgba(91, 84, 230, 0.25);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --maxw: 1080px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 20px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.4em; }
p { margin: 0 0 1em; }

/* ---------- Header / footer ---------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: saturate(180%) blur(8px);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand-mark { font-size: 1.5rem; }
.site-nav { display: flex; gap: 6px; }
.site-nav a {
  color: var(--muted);
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.95rem;
}
.site-nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.site-nav a.active { background: var(--primary-soft); color: var(--primary-dark); }

main#app { flex: 1; padding-top: 28px; padding-bottom: 56px; }

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.85rem;
  padding: 20px 0;
}
.site-footer p { margin: 0; }

/* ---------- Hero ---------- */
.hero {
  background: linear-gradient(135deg, #5b54e6 0%, #7b5be6 50%, #9b54d6 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 38px 34px;
  margin-bottom: 28px;
  box-shadow: var(--shadow-lg);
}
.hero h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); margin-bottom: 10px; }
.hero p { font-size: 1.05rem; max-width: 60ch; margin: 0; opacity: 0.95; }

/* ---------- Summary stat cards ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.stat-card .stat-value { font-size: 1.9rem; font-weight: 800; color: var(--primary-dark); }
.stat-card .stat-label { color: var(--muted); font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; overflow-wrap: anywhere; }

/* ---------- Section heading ---------- */
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
.section-head h2 { font-size: 1.4rem; margin: 0; }
.section-head .sub { color: var(--muted); margin: 0; }

/* ---------- Exercise card grid ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}
.ex-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  cursor: pointer;
  text-align: left;
}
.ex-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); text-decoration: none; }
.ex-card:focus-visible { outline: none; box-shadow: var(--ring); }
.ex-icon {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  font-size: 1.7rem;
  border-radius: 14px;
  margin-bottom: 14px;
}
.ex-card h3 { font-size: 1.15rem; margin-bottom: 4px; color: var(--text); }
.ex-card .tagline { color: var(--muted); font-size: 0.92rem; margin: 0 0 16px; flex: 1; }
.ex-card .ex-foot {
  display: flex; align-items: center; justify-content: space-between;
  border-top: 1px solid var(--border); padding-top: 12px; font-size: 0.85rem;
}
.ex-card .ex-best { color: var(--muted); }
.ex-card .ex-best b { color: var(--text); }
.ex-card .ex-go { color: var(--primary); font-weight: 700; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 700; font-size: 1rem;
  padding: 12px 22px;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease, box-shadow 0.15s;
  background: var(--surface-2); color: var(--text); border-color: var(--border);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-lg { padding: 15px 30px; font-size: 1.08rem; }
.btn-block { width: 100%; }

/* ---------- Back link ---------- */
.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--muted); font-weight: 600; margin-bottom: 18px; font-size: 0.95rem;
  background: none; border: none; cursor: pointer; font-family: inherit; padding: 0;
}
.back-link:hover { color: var(--text); }

/* ---------- Detail / panels ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: var(--shadow);
  margin-bottom: 22px;
}
.detail-head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.detail-head .ex-icon { margin: 0; }
.detail-head h1 { margin: 0; font-size: 1.7rem; }
.detail-head .tagline { margin: 2px 0 0; color: var(--muted); }

.instructions h3 { margin-top: 18px; font-size: 1.05rem; }
.instructions ul, .instructions ol { margin: 0 0 1em; padding-left: 1.3em; }
.instructions li { margin-bottom: 6px; }
.tip {
  background: var(--primary-soft);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 12px 16px;
  color: var(--primary-dark);
  margin: 0 0 1em;
}
.tip b { color: var(--primary-dark); }

/* ---------- Difficulty segmented control ---------- */
.field-label { font-weight: 700; display: block; margin-bottom: 10px; }
.segmented { display: inline-flex; flex-wrap: wrap; gap: 8px; }
.segmented button {
  font: inherit; font-weight: 600;
  padding: 10px 18px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; transition: all 0.12s ease;
}
.segmented button .seg-sub { display: block; font-size: 0.75rem; color: var(--muted); font-weight: 500; }
.segmented button[aria-pressed="true"] { background: var(--primary); color: #fff; border-color: var(--primary); }
.segmented button[aria-pressed="true"] .seg-sub { color: rgba(255,255,255,0.85); }
.segmented button:focus-visible { outline: none; box-shadow: var(--ring); }

/* ---------- Session / play area ---------- */
.play { text-align: center; }
.play .phase-tag {
  display: inline-block; font-size: 0.8rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--primary-dark); background: var(--primary-soft);
  padding: 5px 12px; border-radius: 999px; margin-bottom: 14px;
}
.play h2 { font-size: 1.4rem; }
.play .hint { color: var(--muted); max-width: 56ch; margin: 0 auto 22px; }

/* Countdown timer bar */
.timer { max-width: 460px; margin: 0 auto 26px; }
.timer-num { font-size: 1.05rem; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.timer-bar { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.timer-fill { height: 100%; background: linear-gradient(90deg, var(--primary), #9b54d6); width: 100%; transition: width 1s linear; }

/* Memorize item lists */
.memo-grid { display: grid; gap: 12px; max-width: 620px; margin: 0 auto 26px; }
.memo-row {
  display: flex; align-items: center; gap: 14px; text-align: left;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 16px;
}
.memo-row .memo-loc { font-weight: 700; color: var(--primary-dark); min-width: 0; flex: 0 0 38%; }
.memo-row .memo-item { font-weight: 700; font-size: 1.05rem; }
.memo-row .memo-arrow { color: var(--muted); }

/* Big number/word display */
.bigdisplay {
  font-weight: 800;
  letter-spacing: 0.12em;
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.8rem, 7vw, 3.2rem);
  margin: 18px auto 26px;
  word-break: break-word;
}
.bigdisplay .chunk { display: inline-block; margin: 0 0.18em; }
.wordflash { font-size: clamp(2rem, 8vw, 3.4rem); font-weight: 800; min-height: 1.4em; }

/* Recall input rows */
.recall-grid { display: grid; gap: 12px; max-width: 560px; margin: 0 auto 24px; text-align: left; }
.recall-row { display: flex; align-items: center; gap: 12px; }
.recall-row label { flex: 0 0 40%; font-weight: 600; color: var(--muted); }
.recall-row .cue { color: var(--primary-dark); font-weight: 700; }
input[type="text"], input[type="number"] {
  font: inherit; flex: 1; width: 100%;
  padding: 11px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
input[type="text"]:focus, input[type="number"]:focus { outline: none; box-shadow: var(--ring); border-color: var(--primary); }
.recall-single { max-width: 480px; margin: 0 auto 22px; }
.recall-single input { text-align: center; font-size: 1.4rem; letter-spacing: 0.15em; font-variant-numeric: tabular-nums; }

textarea.note {
  font: inherit; width: 100%; max-width: 560px; margin: 0 auto 22px; display: block;
  padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); resize: vertical; min-height: 70px;
}

.play-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }

/* ---------- Playing cards ---------- */
.card-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 18px auto 26px; }
.pcard {
  width: 58px; height: 80px; border-radius: 9px;
  background: #fff; border: 1px solid #d4d7e4;
  box-shadow: 0 2px 5px rgba(0,0,0,0.08);
  display: grid; place-items: center; font-size: 1.05rem; font-weight: 800;
  position: relative; user-select: none;
}
.pcard .rank { position: absolute; top: 5px; left: 7px; font-size: 0.85rem; }
.pcard .suit-big { font-size: 1.7rem; }
.pcard.red { color: #d62839; }
.pcard.black { color: #1d2233; }
.pcard.slot { background: var(--surface-2); border: 2px dashed var(--border); color: var(--muted); box-shadow: none; }
.pcard.pick { cursor: pointer; transition: transform 0.1s; }
.pcard.pick:hover { transform: translateY(-3px); }
.pcard.used { opacity: 0.25; pointer-events: none; }
.card-pick-wrap { display: flex; flex-direction: column; gap: 14px; align-items: center; }
.card-pick-wrap .lbl { font-weight: 600; color: var(--muted); }

/* ---------- Result screen ---------- */
.result-head { text-align: center; margin-bottom: 22px; }
.score-ring {
  --pct: 0;
  width: 132px; height: 132px; border-radius: 50%;
  margin: 0 auto 16px;
  background: conic-gradient(var(--primary) calc(var(--pct) * 1%), var(--border) 0);
  display: grid; place-items: center;
}
.score-ring .inner {
  width: 104px; height: 104px; border-radius: 50%; background: var(--surface);
  display: grid; place-items: center; flex-direction: column; text-align: center;
}
.score-ring .pct { font-size: 1.9rem; font-weight: 800; color: var(--primary-dark); line-height: 1; }
.score-ring .frac { font-size: 0.8rem; color: var(--muted); }
.result-msg { font-size: 1.15rem; font-weight: 700; }

.breakdown { max-width: 560px; margin: 0 auto 24px; display: grid; gap: 8px; }
.bd-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border); text-align: left;
}
.bd-row.ok { background: var(--success-soft); border-color: #bbf7d0; }
.bd-row.bad { background: var(--danger-soft); border-color: #f8c6cd; }
.bd-row .bd-mark { font-size: 1.1rem; flex: 0 0 auto; }
.bd-row .bd-label { color: var(--muted); flex: 0 0 34%; font-weight: 600; }
.bd-row .bd-vals { flex: 1; }
.bd-row .bd-got.wrong { color: var(--danger); text-decoration: line-through; opacity: 0.8; }
.bd-row .bd-exp { font-weight: 700; }

/* ---------- Progress page ---------- */
.progress-row {
  display: flex; align-items: center; gap: 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.progress-row .ex-icon { margin: 0; width: 46px; height: 46px; font-size: 1.4rem; }
.progress-row .pr-info { flex: 1; min-width: 0; }
.progress-row .pr-info h3 { margin: 0 0 2px; font-size: 1.05rem; }
.progress-row .pr-info p { margin: 0; color: var(--muted); font-size: 0.9rem; }
.progress-row .pr-stats { display: flex; gap: 22px; text-align: center; }
.progress-row .pr-stats .v { font-weight: 800; font-size: 1.2rem; color: var(--primary-dark); }
.progress-row .pr-stats .k { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }

/* Sparkline-ish bar chart */
.spark { display: flex; align-items: flex-end; gap: 3px; height: 40px; }
.spark .b { width: 7px; background: var(--primary-soft); border-radius: 3px 3px 0 0; }
.spark .b.good { background: var(--primary); }

.empty-state { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ---------- Toast feedback ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: #fff; padding: 12px 22px; border-radius: 999px;
  font-weight: 600; box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Utilities ---------- */
.mt-0 { margin-top: 0; }
.center { text-align: center; }
.muted { color: var(--muted); }
.row-wrap { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.fade-in { animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .hero { padding: 28px 22px; }
  .panel { padding: 20px; }
  .recall-row { flex-direction: column; align-items: stretch; gap: 6px; }
  .recall-row label { flex: none; }
  .progress-row { flex-wrap: wrap; }
  .progress-row .pr-stats { gap: 18px; }
  .memo-row .memo-loc { flex-basis: 42%; }
  .site-footer { font-size: 0.8rem; }
}

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