/* Home Hub. Every colour, font and corner comes from the theme tokens below;
   the four themes only change tokens plus a few decorations at the end. */

:root, [data-theme="professor"] {
  --bg: #EFE7D4; --bg-img: radial-gradient(#0000 0 60%, #7a5a2a10 100%), repeating-linear-gradient(0deg, #0000 0 3px, #8a6a3a08 3px 4px);
  --surface: #FBF7EC; --surface-2: #F3ECDA; --ink: #2B2118; --muted: #6B5B48; --line: #D8CBAE;
  --accent: #7A1F2B; --accent-ink: #FBF7EC; --accent-2: #2F4A3A; --accent-2-ink: #F4EEDF; --good: #2F6B3A; --danger: #9B2226;
  --bar-bg: #2F4A3A; --bar-ink: #F4EEDF;
  --font-body: "EB Garamond", Georgia, serif; --font-head: "EB Garamond", Georgia, serif; --font-tag: "Special Elite", "Courier New", monospace;
  --body-size: 17px; --head-weight: 700; --head-case: none; --head-track: .01em;
  --r: 4px; --r-btn: 3px; --shadow: 0 1px 0 #fff8 inset, 0 2px 6px #4a351a1f;
  --paper: #FDF8D8; --paper-line: #B9CBE0; --paper-margin: #D98C8C; --pen: #1F3A68;
}

[data-theme="girly"] {
  --bg: #FFEFF5; --bg-img: radial-gradient(#F7B6CF55 1.6px, #0000 1.8px) 0 0/22px 22px;
  --surface: #FFFFFF; --surface-2: #FFF5F9; --ink: #4A2340; --muted: #8A5C7C; --line: #F5C9DB;
  --accent: #D63A78; --accent-ink: #FFFFFF; --accent-2: #9B6FD6; --accent-2-ink: #FFFFFF; --good: #2E8B6A; --danger: #C0284F;
  --bar-bg: linear-gradient(90deg, #F9A8C9, #CDB4F5); --bar-ink: #4A2340;
  --font-body: "Quicksand", system-ui, sans-serif; --font-head: "Pacifico", cursive; --font-tag: "Quicksand", sans-serif;
  --body-size: 16px; --head-weight: 400; --head-case: none; --head-track: 0;
  --r: 22px; --r-btn: 999px; --shadow: 0 6px 18px #D63A7820;
  --paper: #FFFFFF; --paper-line: #F9D3E2; --paper-margin: #CDB4F5; --pen: #8A2C63;
}

[data-theme="manly"] {
  --bg: #1B1D1F; --bg-img: repeating-linear-gradient(90deg, #ffffff05 0 1px, #0000 1px 4px), linear-gradient(#232628, #16181A);
  --surface: #2A2D30; --surface-2: #33373B; --ink: #ECE6DA; --muted: #A69F92; --line: #44494E;
  --accent: #D9652B; --accent-ink: #1B1D1F; --accent-2: #8A9A4B; --accent-2-ink: #16180F; --good: #9DBB55; --danger: #E2553F;
  --bar-bg: #121314; --bar-ink: #ECE6DA;
  --font-body: "Roboto Condensed", "Arial Narrow", sans-serif; --font-head: "Oswald", Impact, sans-serif; --font-tag: "Oswald", sans-serif;
  --body-size: 16px; --head-weight: 700; --head-case: uppercase; --head-track: .06em;
  --r: 2px; --r-btn: 2px; --shadow: 0 3px 0 #0006, 0 0 0 1px #000 inset;
  --paper: #C9A97A; --paper-line: #A88858; --paper-margin: #8E3B1E; --pen: #2A1C0E;
  color-scheme: dark;
}

[data-theme="nerd"] {
  --bg: #070B08; --bg-img: radial-gradient(#39FF6A10 1px, #0000 1px) 0 0/16px 16px;
  --surface: #0C130E; --surface-2: #101A13; --ink: #B6F5C2; --muted: #6FA37C; --line: #1F3A26;
  --accent: #39FF6A; --accent-ink: #04140A; --accent-2: #FFB000; --accent-2-ink: #1A1000; --good: #39FF6A; --danger: #FF5470;
  --bar-bg: #0A110C; --bar-ink: #39FF6A;
  --font-body: "JetBrains Mono", ui-monospace, Menlo, monospace; --font-head: "VT323", "JetBrains Mono", monospace; --font-tag: "JetBrains Mono", monospace;
  --body-size: 14px; --head-weight: 400; --head-case: none; --head-track: .02em;
  --r: 0; --r-btn: 0; --shadow: 0 0 0 1px #39FF6A33, 0 0 18px #39FF6A14;
  --paper: #0C130E; --paper-line: #16261A; --paper-margin: #FFB00055; --pen: #FFB000;
  color-scheme: dark;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg-img), var(--bg); background-color: var(--bg); background-attachment: fixed;
  color: var(--ink); font: var(--body-size)/1.45 var(--font-body);
  min-height: 100vh; -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--font-head); font-weight: var(--head-weight); text-transform: var(--head-case); letter-spacing: var(--head-track); margin: 0; line-height: 1.15; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
input, select, textarea, button { font: inherit; color: inherit; }
input:not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%; background: var(--surface-2); border: 1px solid var(--line); border-radius: min(var(--r), 10px);
  padding: 9px 11px; color: var(--ink);
}
:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: var(--r-btn); padding: 8px 14px; cursor: pointer; font-weight: 700; white-space: nowrap;
  text-decoration: none;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { padding: 5px 10px; font-size: .88em; }
.btn.danger { color: var(--danger); }
.iconbtn { width: 40px; padding: 8px 0; }
.linkbtn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 4px 0; font-weight: 700; }
.error { color: var(--danger); min-height: 1.2em; margin: 4px 0; }

/* ---------- sign in ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.authcard { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 28px; display: grid; gap: 12px; }
.authcard h1 { font-size: 1.9rem; }
.authcard label { display: grid; gap: 4px; font-weight: 700; font-size: .92em; }
.brand { display: flex; align-items: center; gap: 10px; font: var(--head-weight) 1.35rem var(--font-head); text-transform: var(--head-case); letter-spacing: var(--head-track); }
.logo { width: 30px; height: 30px; flex: none; border-radius: min(var(--r), 8px); background: var(--accent);
  -webkit-mask: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><path d='M3 16 16 4l13 12h-4v12h-7v-8h-4v8H7V16z'/></svg>") center/contain no-repeat;
          mask: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><path d='M3 16 16 4l13 12h-4v12h-7v-8h-4v8H7V16z'/></svg>") center/contain no-repeat; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 10; background: var(--bar-bg); color: var(--bar-ink);
  display: flex; align-items: center; gap: 12px 18px; flex-wrap: wrap;
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  box-shadow: 0 2px 10px #0002;
}
.top .logo { background: currentColor; }
.hello { margin: 0; flex: 1; min-width: 140px; opacity: .9; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.themepick select { width: auto; padding: 7px 10px; border-radius: var(--r-btn); background: var(--surface); font-weight: 700; }
.ico { font-weight: 400; }

/* ---------- page layout: dashboard + notepad ---------- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; padding: 20px max(16px, env(safe-area-inset-right)) 40px max(16px, env(safe-area-inset-left)); max-width: 1500px; margin: 0 auto; }
.layout.nopad { grid-template-columns: minmax(0, 1fr); }
@media (max-width: 900px) { .layout { grid-template-columns: minmax(0, 1fr); } }
.dash { min-width: 0; display: grid; gap: 20px; align-content: start; }

/* ---------- cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; align-items: start; }
@media (max-width: 400px) { .cards { grid-template-columns: minmax(0, 1fr); } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.card.wide { grid-column: 1 / -1; }
.card.dragging { opacity: .45; }
.card.dropbefore { box-shadow: -4px 0 0 var(--accent), var(--shadow); }
.cardhead { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.cardhead h2 { font-size: 1.3rem; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.grip { cursor: grab; color: var(--muted); border: 0; background: none; padding: 2px 4px; font-size: 1.1rem; line-height: 1; }
.cardbody { padding: 14px; display: grid; gap: 12px; }
.cardmenu { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 5; background: var(--surface); border: 1px solid var(--line); border-radius: min(var(--r), 10px); box-shadow: 0 8px 24px #0003; display: grid; min-width: 180px; padding: 4px; }
.menu button { text-align: left; border: 0; background: none; padding: 8px 10px; cursor: pointer; border-radius: min(var(--r), 6px); }
.menu button:hover { background: var(--surface-2); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > input, .row > select { flex: 1; min-width: 0; }
.tag { font: 700 .72rem var(--font-tag); letter-spacing: .06em; text-transform: uppercase; color: var(--accent-2); }
.empty { color: var(--muted); font-style: italic; margin: 0; }

/* calendar */
.daygroup { display: grid; gap: 6px; }
.daygroup h3 { font: 700 .78rem var(--font-tag); letter-spacing: .08em; text-transform: uppercase; color: var(--accent); border-bottom: 1px dashed var(--line); padding-bottom: 3px; }
.ev { display: grid; grid-template-columns: 74px minmax(0, 1fr) auto; gap: 8px; align-items: start; }
.ev time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .9em; padding-top: 1px; }
.ev b { font-weight: 700; overflow-wrap: anywhere; }
.ev small { display: block; color: var(--muted); }
.ev .x { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1.1rem; line-height: 1; padding: 0 2px; }
.ev .x:hover { color: var(--danger); }
.src { font-size: .7rem; font-weight: 700; padding: 1px 6px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.status { font-size: .88em; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--good); }

/* food */
.meter { display: grid; gap: 4px; }
.meter .nums { display: flex; justify-content: space-between; align-items: baseline; }
.meter .big { font: var(--head-weight) 2rem/1 var(--font-head); color: var(--accent); }
.bar { height: 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.bar.over > span { background: var(--danger); }
.macros { display: flex; gap: 14px; font-size: .88em; color: var(--muted); }
.foods { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.foods li { display: flex; gap: 8px; align-items: center; }
.foods img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex: none; }
.foods .nm { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.foods .cal { font-variant-numeric: tabular-nums; font-weight: 700; }

/* embedded apps */
.frame { width: 100%; height: 560px; border: 1px solid var(--line); border-radius: min(var(--r), 8px); background: #fff; }
.applink { display: flex; gap: 12px; align-items: center; }
.appicon { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: min(var(--r), 12px); background: var(--accent-2); color: var(--accent-2-ink); font: var(--head-weight) 1.3rem var(--font-head); }

/* ---------- sticky notes ---------- */
.stickies { display: flex; gap: 18px; flex-wrap: wrap; padding: 6px 2px 4px; }
.sticky {
  --c: #FFF27A; --ci: #3B3300;
  width: 200px; min-height: 160px; padding: 14px 14px 10px; background: var(--c); color: var(--ci);
  box-shadow: 0 10px 14px -8px #0006, 0 1px 2px #0002; display: flex; flex-direction: column; gap: 6px;
  transform: rotate(var(--tilt, -1.5deg)); position: relative; border-radius: 2px 2px 14px 2px;
}
.sticky::before { content: ""; position: absolute; top: -9px; left: 50%; width: 70px; height: 20px; transform: translateX(-50%) rotate(-3deg); background: #ffffff8c; box-shadow: 0 1px 2px #0002; }
.sticky p { margin: 0; font: 600 1.35rem/1.15 "Caveat", "Bradley Hand", cursive; flex: 1; overflow-wrap: anywhere; white-space: pre-wrap; }
.sticky footer { display: flex; justify-content: space-between; align-items: center; font-size: .78rem; opacity: .8; gap: 6px; }
.sticky .x { border: 0; background: #0000001a; color: inherit; width: 24px; height: 24px; border-radius: 50%; cursor: pointer; line-height: 1; }
.sticky .new { position: absolute; top: -8px; right: -8px; background: var(--accent); color: var(--accent-ink); font: 700 .7rem var(--font-body); padding: 2px 7px; border-radius: 999px; transform: rotate(6deg); }
.sticky.pink   { --c: #FFC2DA; --ci: #4A0F2A; }
.sticky.blue   { --c: #BFE3FF; --ci: #0B2D4A; }
.sticky.green  { --c: #C8F2B4; --ci: #183B0B; }
.sticky.orange { --c: #FFD3A3; --ci: #4A2405; }
.sticky.purple { --c: #DCCBFF; --ci: #2B1257; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches label { width: 34px; height: 34px; border-radius: 50%; cursor: pointer; border: 2px solid #0002; display: grid; place-items: center; }
.swatches input { position: absolute; opacity: 0; }
.swatches label:has(input:checked) { outline: 3px solid var(--accent); outline-offset: 2px; }
.swatches label:has(input:focus-visible) { outline: 3px solid var(--accent-2); outline-offset: 2px; }

/* ---------- notepad ---------- */
.pad { min-width: 0; }
.padsheet {
  position: sticky; top: 80px; background-color: var(--paper); color: var(--pen);
  background-image: linear-gradient(90deg, #0000 30px, var(--paper-margin) 30px 32px, #0000 32px),
                    repeating-linear-gradient(#0000 0 31px, var(--paper-line) 31px 32px);
  border-radius: min(var(--r), 6px); box-shadow: var(--shadow); padding: 16px 14px 16px 44px; display: grid; gap: 10px;
  border: 1px solid var(--line);
}
.padsheet h2 { font: 600 1.7rem/32px "Caveat", cursive; color: var(--pen); text-transform: none; letter-spacing: 0; }
.todoform { display: flex; gap: 6px; }
.todoform input { background: #ffffff66; }
.todos { list-style: none; margin: 0; padding: 0; }
.todos li { display: flex; gap: 8px; align-items: center; min-height: 32px; }
.todos input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); flex: none; margin: 0; }
.todos .t { flex: 1; min-width: 0; font: 600 1.25rem/1.1 "Caveat", cursive; overflow-wrap: anywhere; cursor: text; }
.todos li.done .t { text-decoration: line-through; opacity: .55; }
.todos .x { border: 0; background: none; color: inherit; opacity: .45; cursor: pointer; font-size: 1.1rem; }
.todos .x:hover { opacity: 1; }
#notepad { min-height: 220px; resize: vertical; background: transparent; border: 0; padding: 0; color: var(--pen); font: 600 1.25rem/32px "Caveat", cursive; }
.saved { font-size: .78rem; margin: 0; min-height: 1em; }

/* ---------- dialogs ---------- */
dialog { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--ink); padding: 0; width: min(520px, calc(100% - 32px)); box-shadow: 0 20px 60px #0005; }
dialog::backdrop { background: #0008; }
#dlgForm { padding: 20px; display: grid; gap: 14px; max-height: 85vh; overflow: auto; }
#dlgForm h2 { font-size: 1.5rem; }
#dlgForm label { display: grid; gap: 4px; font-weight: 700; font-size: .92em; }
#dlgForm label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.dlgbtns { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 460px) { .grid2 { grid-template-columns: 1fr; } }
.pick { display: grid; gap: 8px; }
.pick label { display: flex !important; gap: 12px; align-items: flex-start; border: 1px solid var(--line); border-radius: min(var(--r), 10px); padding: 10px 12px; cursor: pointer; font-weight: 400 !important; }
.pick label:has(input:checked) { border-color: var(--accent); background: var(--surface-2); }
.pick b { display: block; }
.section { border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 8px; }
.section h3 { font-size: 1.1rem; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.list li { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.copybox { font-family: ui-monospace, Menlo, monospace; font-size: .85em; word-break: break-all; }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: var(--r-btn); font-weight: 700; z-index: 50; max-width: calc(100% - 32px); text-align: center; box-shadow: 0 6px 20px #0004; }

/* ---------- theme decorations ---------- */

/* professor: index cards with a red rule, chalkboard header */
[data-theme="professor"] .cardhead { border-bottom: 2px solid var(--accent); box-shadow: 0 3px 0 -1px var(--surface), 0 4px 0 -1px var(--line); }
[data-theme="professor"] .cardhead h2 { font-variant: small-caps; letter-spacing: .03em; }
[data-theme="professor"] .top { border-bottom: 4px solid #B08D57; }
[data-theme="professor"] .top .brand { font-style: italic; }
[data-theme="professor"] .hello { font-style: italic; }

/* girly: soft and rounded, little hearts */
[data-theme="girly"] .cardhead { background: var(--surface-2); border-bottom-style: dashed; }
[data-theme="girly"] .cardhead h2 { color: var(--accent); font-size: 1.25rem; }
[data-theme="girly"] .cardhead h2::after { content: " ♡"; color: var(--accent-2); }
[data-theme="girly"] .btn.primary { background: linear-gradient(135deg, #F06A9F, #B98AE8); border-color: transparent; }
[data-theme="girly"] .daygroup h3 { border-bottom-style: dotted; }
[data-theme="girly"] .top .brand { font-family: "Pacifico", cursive; }

/* manly: steel plates with rivets, stencil headings */
[data-theme="manly"] .card { border: 2px solid #111; position: relative; }
[data-theme="manly"] .cardhead { background: linear-gradient(#3A3E42, #2E3134); border-bottom: 2px solid var(--accent); }
[data-theme="manly"] .card::before, [data-theme="manly"] .card::after { content: ""; position: absolute; top: 6px; width: 6px; height: 6px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #9a9a9a, #3b3b3b); }
[data-theme="manly"] .card::before { left: 6px; } [data-theme="manly"] .card::after { right: 6px; }
[data-theme="manly"] .cardhead { padding-inline: 20px; }
[data-theme="manly"] .top { border-bottom: 3px solid var(--accent); }
[data-theme="manly"] .btn { text-transform: uppercase; letter-spacing: .05em; font-family: var(--font-head); font-weight: 500; }
[data-theme="manly"] .padsheet { background-image: repeating-linear-gradient(#0000 0 31px, var(--paper-line) 31px 32px), linear-gradient(90deg, #0000 30px, var(--paper-margin) 30px 32px, #0000 32px); filter: saturate(.9); }

/* computer nerd: terminal windows, glow and scanlines */
[data-theme="nerd"] .fx { position: fixed; inset: 0; pointer-events: none; z-index: 100; background: repeating-linear-gradient(#0000 0 2px, #00000038 2px 3px); }
[data-theme="nerd"] .cardhead { background: #0F2014; padding-block: 6px; }
[data-theme="nerd"] .cardhead h2 { font-size: 1.5rem; color: var(--accent); text-shadow: 0 0 8px #39FF6A88; }
[data-theme="nerd"] .cardhead h2::before { content: "~/"; color: var(--accent-2); }
[data-theme="nerd"] .cardhead h2::after { content: " $_"; color: var(--muted); animation: blink 1.1s steps(1) infinite; }
[data-theme="nerd"] .top .brand { font-size: 1.7rem; text-shadow: 0 0 10px #39FF6A99; }
[data-theme="nerd"] .top .brand::before { content: ">"; color: var(--accent-2); }
[data-theme="nerd"] .top .logo { display: none; }
[data-theme="nerd"] .top { border-bottom: 1px solid var(--accent); }
[data-theme="nerd"] .padsheet h2, [data-theme="nerd"] .todos .t, [data-theme="nerd"] #notepad { font-family: "VT323", monospace; font-size: 1.35rem; }
[data-theme="nerd"] .btn.primary { box-shadow: 0 0 12px #39FF6A66; }
[data-theme="nerd"] .frame { filter: none; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { [data-theme="nerd"] .cardhead h2::after { animation: none; } }
