:root {
  --bg: #0f1e1d;
  --surface: #16302e;
  --surface-2: #1d3d3a;
  --line: #2c5551;
  --text: #eef5f4;
  --muted: #9fc2be;
  --accent: #38b2a6;
  --accent-ink: #04201d;
  --warn: #ffd27a;
  --radius: 18px;
  --tap: 56px;
  font-size: 18px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app { max-width: 640px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

.screen { padding: 20px 18px 40px; flex: 1; display: flex; flex-direction: column; gap: 18px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.topbar h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: .2px; }
.topbar .back { background: none; border: none; color: var(--accent); font-size: 1rem; padding: 8px; min-height: var(--tap); }

h2 { font-size: 1.35rem; line-height: 1.35; }
p.lead { color: var(--muted); font-size: 1rem; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: var(--radius);
  min-height: var(--tap);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  padding: 14px 18px;
}
button:active { transform: scale(.99); }

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 700;
  font-size: 1.1rem;
}
.btn-big { width: 100%; min-height: 88px; font-size: 1.25rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-row button { flex: 1 1 45%; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

/* Login / PIN */
.pin-wrap { margin: auto; text-align: center; display: flex; flex-direction: column; gap: 22px; width: 100%; max-width: 320px; }
.pin-dots { display: flex; gap: 14px; justify-content: center; }
.pin-dots span { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--accent); }
.pin-dots span.on { background: var(--accent); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.keypad button { min-height: 68px; font-size: 1.5rem; font-weight: 600; }
.error { color: var(--warn); min-height: 1.4em; }

/* Ny opgave */
.pick { display: flex; flex-direction: column; gap: 12px; }
textarea {
  width: 100%; min-height: 120px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; resize: vertical;
}
.thumbs { display: flex; flex-wrap: wrap; gap: 10px; }
.thumbs figure { position: relative; cursor: pointer; }
.thumbs img { width: 84px; height: 84px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); display: block; }
.thumbs .rm { position: absolute; top: -8px; right: -8px; min-height: 28px; width: 28px; padding: 0; border-radius: 50%; background: var(--warn); color: #000; border: none; font-weight: 700; }
.thumbs .crop-tag {
  position: absolute; left: 0; right: 0; bottom: 0;
  font-size: .7rem; text-align: center; padding: 3px 0;
  background: rgba(0,0,0,.55); color: #fff;
  border-bottom-left-radius: 12px; border-bottom-right-radius: 12px;
}

/* Forklaring */
.steps { display: flex; flex-direction: column; gap: 14px; }
.step-head { display: flex; align-items: baseline; gap: 10px; }
.step-num {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700; font-size: .95rem;
}
.step h3 { font-size: 1.1rem; }
.step .body { margin-top: 8px; }
.step .body p { margin: .4em 0; }

.check-card { background: var(--surface-2); border-color: var(--accent); }
.check-card h3 { color: var(--warn); font-size: 1.05rem; margin-bottom: 6px; }

.reveal-btn { width: 100%; }
.spinner { text-align: center; color: var(--muted); padding: 30px; }
.dots::after { content: ''; animation: dots 1.2s steps(4, end) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

/* Historik */
.history { display: flex; flex-direction: column; gap: 10px; }
.history a {
  display: block; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
}
.history .topic { color: var(--muted); font-size: .85rem; }
.history .row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.history .del { background: none; border: none; color: var(--muted); min-height: 40px; padding: 6px 10px; }


mjx-container { overflow-x: auto; overflow-y: hidden; max-width: 100%; }

/* Whiteboard */
.wb-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom);
}
.wb-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 0; }
.wb-bar .back { flex: 0 0 auto; }
.wb-bar .btn-primary { flex: 0 0 auto; min-height: 48px; }
.wb-tools { display: flex; flex-wrap: wrap; gap: 8px; flex: 1 1 100%; order: 3; }
.wb-tools button { flex: 1 1 auto; min-height: 48px; padding: 8px 10px; font-size: .95rem; }
.wb-tool.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.wb-stage { flex: 1; min-height: 0; display: flex; }
#wbCanvas {
  flex: 1; width: 100%; height: 100%;
  background: #fff; border-radius: 12px; border: 1px solid var(--line);
  touch-action: none; cursor: crosshair;
}
.wb-hint { text-align: center; padding: 8px 0; }

/* Kamera */
.cam-overlay {
  position: fixed; inset: 0; z-index: 50; background: #000;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.cam-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
#camVid { max-width: 100%; max-height: 100%; }
.cam-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; }
.cam-bar .back { color: #fff; }
.cam-bar .btn-primary { flex: 1; max-width: 260px; }

/* Beskær */
.crop-overlay {
  position: fixed; inset: 0; z-index: 51; background: var(--bg);
  display: flex; flex-direction: column;
  padding: max(env(safe-area-inset-top), 10px) 12px max(env(safe-area-inset-bottom), 10px);
}
.crop-bar {
  display: flex; flex-wrap: nowrap; align-items: center; gap: 8px;
  padding: 8px 0 12px; position: relative; z-index: 2; background: var(--bg);
}
.crop-bar button { min-height: 48px; padding: 8px 12px; white-space: nowrap; }
.crop-bar .back { flex: 0 0 auto; }
.crop-bar #crFull { flex: 1 1 auto; }
.crop-bar .btn-primary { flex: 0 0 auto; }
.crop-stage {
  flex: 1; min-height: 0; position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: 22px; overflow: hidden; touch-action: none;
}
#crImg { max-width: 100%; max-height: 100%; object-fit: contain; display: block; -webkit-user-select: none; user-select: none; -webkit-user-drag: none; }
.crop-box { position: absolute; border: 2px solid var(--accent); box-shadow: 0 0 0 9999px rgba(0,0,0,.55); touch-action: none; }
.crop-h { position: absolute; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); border: 2px solid #fff; touch-action: none; }
.crop-h.nw { left: -14px; top: -14px; }
.crop-h.ne { right: -14px; top: -14px; }
.crop-h.sw { left: -14px; bottom: -14px; }
.crop-h.se { right: -14px; bottom: -14px; }
.crop-hint { text-align: center; padding: 8px 0; }

.hidden { display: none !important; }
