@font-face {
  font-family: "Caveat";
  src: url("fonts/Caveat.ttf") format("truetype");
  font-weight: 400 700;
  font-display: swap;
}
/* Kurdish / Arabic script. Listed after Caveat, so Latin letters stay
   handwritten and Kurdish letters use Amiri. */
@font-face {
  font-family: "Amiri";
  src: url("fonts/Amiri-Regular.ttf") format("truetype");
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/JetBrainsMono.ttf") format("truetype");
  font-weight: 100 800;
  font-display: swap;
}

/* Gruvbox Dark Soft */
:root,
:root[data-theme="dark"] {
  --bg: #32302f;
  --bg1: #3c3836;
  --bg2: #504945;
  --fg: #ebdbb2;
  --muted: #a89984;
  --line: #665c54;
  --red: #fb4934;
  --green: #b8bb26;
  --yellow: #fabd2f;
  --blue: #83a598;
  --purple: #d3869b;
  --aqua: #8ec07c;
  --orange: #fe8019;
  --accent: var(--orange);
  color-scheme: dark;
}

/* Gruvbox Light Soft */
:root[data-theme="light"] {
  --bg: #f2e5bc;
  --bg1: #ebdbb2;
  --bg2: #d5c4a1;
  --fg: #3c3836;
  --muted: #7c6f64;
  --line: #bdae93;
  --red: #9d0006;
  --green: #79740e;
  --yellow: #b57614;
  --blue: #076678;
  --purple: #8f3f71;
  --aqua: #427b58;
  --orange: #af3a03;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 14px;
}

.hand { font-family: "Caveat", "Amiri", cursive; }

button {
  font: inherit;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  height: 30px;
  min-width: 30px;
  padding: 0 9px;
  cursor: pointer;
}
button:hover, button[aria-expanded="true"] { background: var(--bg1); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

#page {
  display: grid;
  grid-template-columns: minmax(0, 42fr) minmax(0, 58fr);
  /* The middle row fills the window when there's room, and grows (the
     page scrolls) when the schedule needs more height than the window has. */
  grid-template-rows: auto auto 1fr auto;
  grid-template-areas:
    "top top"
    "locked locked"
    "left right"
    "foot foot";
  column-gap: 36px;
  row-gap: 18px;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px 28px 14px;
  background: var(--bg);
}

/* ---- header ---- */
.top {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 16px; }
.badge {
  width: 60px; height: 60px;
  background: var(--fg); color: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 700; line-height: 1;
}
#badge-day { font-size: 26px; }
#badge-month { font-size: 10px; letter-spacing: 2px; margin-top: 3px; }
h1 { font-size: 26px; margin: 0; font-weight: 700; white-space: nowrap; }
.dateline {
  flex: 1 1 260px;
  display: flex; align-items: flex-end; gap: 14px;
  min-width: 0;
}
.date-label { font-weight: 700; padding-bottom: 6px; }
.date-text {
  flex: 1; min-width: 0;
  font-size: 32px; text-align: center;
  border-bottom: 1px solid var(--fg);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.controls { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.menu-wrap { position: relative; }
/* Download link for the Android app: phones only, and not inside the app. */
.apk-link {
  display: none; align-items: center; height: 30px; padding: 0 9px;
  border: 1px solid var(--accent); border-radius: 4px;
  color: var(--accent); text-decoration: none;
}
@media (max-width: 860px) { .apk-link { display: inline-flex; } }
@media (display-mode: standalone) { .apk-link { display: none !important; } }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
  display: flex; flex-wrap: wrap; gap: 6px; padding: 8px;
  width: max-content; max-width: calc(100vw - 16px);
  background: var(--bg); border: 1px solid var(--line); border-radius: 4px;
  box-shadow: 0 6px 18px rgb(0 0 0 / .25);
}
.menu[hidden] { display: none; }
.menu button { display: flex; align-items: center; gap: 6px; border-color: transparent; }
.dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); vertical-align: middle; }
.swatch { width: 24px; height: 24px; min-width: 24px; padding: 0; border-radius: 50%; border: 2px solid transparent; }
.swatch.current { border-color: var(--fg); }
.ink-btn { font-weight: 700; text-decoration: underline; text-decoration-color: var(--red); text-decoration-thickness: 3px; text-underline-offset: 3px; }

.locked {
  grid-area: locked;
  color: var(--red); border: 1px solid var(--red); border-radius: 4px; padding: 8px 12px;
}

/* ---- left column ---- */
.left { grid-area: left; display: flex; flex-direction: column; }
h2 { font-size: 17px; margin: 0 0 10px; font-weight: 700; }
.priorities { border: 1px solid var(--line); margin-bottom: 24px; }
.prio { display: flex; align-items: center; gap: 14px; height: 52px; padding: 0 16px; }
.prio + .prio { border-top: 1px solid var(--line); }
.check {
  width: 18px; height: 18px; min-width: 18px; padding: 0;
  border-radius: 50%; border: 2px solid var(--muted);
}
.check.done { background: var(--accent); border-color: var(--accent); }
.prio input {
  flex: 1; min-width: 0;
  background: transparent; border: 0; outline: 0;
  color: var(--ink, var(--fg));
  font-family: "Caveat", "Amiri", cursive; font-size: 27px;
  text-align: start;
}
.prio input::placeholder { color: var(--muted); opacity: .6; }
.prio.done input { text-decoration: line-through; opacity: .5; }

.dump {
  flex: 1; min-height: 220px;
  display: grid; grid-template-columns: 1fr 1px 1fr;
  border: 1px solid var(--line);
  background-color: color-mix(in srgb, var(--fg) 3%, var(--bg));
  background-image: radial-gradient(color-mix(in srgb, var(--fg) 22%, transparent) 1px, transparent 1.5px);
  background-size: 22px 22px;
  background-position: 11px 11px;
}
.dump-col {
  padding: 14px 16px; overflow-y: auto; outline: 0;
  font-size: 24px; line-height: 1.35; min-height: 0;
  overflow-wrap: anywhere;
}
.dump-divider { background: var(--line); margin: 10px 0; }
/* Each line takes its own direction: Kurdish right-to-left, English left-to-right. */
.dump-col, .dump-col div { unicode-bidi: plaintext; text-align: start; }
.dump-col.empty::before { content: attr(data-placeholder); color: var(--muted); opacity: .6; pointer-events: none; }
[data-ink="red"] { color: var(--red); }
[data-ink="orange"] { color: var(--orange); }
[data-ink="yellow"] { color: var(--yellow); }
[data-ink="green"] { color: var(--green); }
[data-ink="aqua"] { color: var(--aqua); }
[data-ink="blue"] { color: var(--blue); }
[data-ink="purple"] { color: var(--purple); }

/* ---- schedule ---- */
.right { grid-area: right; display: flex; flex-direction: column; }
.colhead, .grid { display: grid; grid-template-columns: 50px 1fr 1fr; }
.colhead { font-weight: 700; text-align: center; padding-bottom: 10px; }
.grid-wrap { position: relative; flex: 1; display: flex; flex-direction: column; }
.grid {
  flex: 1;
  /* Never shorter than 17 rows, so rows can't spill past the border. */
  min-height: calc(17 * 34px + 2px);
  grid-template-rows: repeat(17, minmax(34px, 1fr));
  border: 1px solid var(--line);
  outline: 0;
  user-select: none;
  touch-action: manipulation;
}
.hour {
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; background: color-mix(in srgb, var(--fg) 5%, var(--bg));
  border-right: 1px solid var(--line);
}
.hour.now { color: var(--accent); }
.cell { position: relative; overflow: visible; cursor: cell; }
.hour, .cell { border-bottom: 1px solid var(--line); }
.cell.c0 { border-right: 1px solid var(--line); }
.grid > :nth-last-child(-n + 3) { border-bottom: 0; }
.cell .fill { position: absolute; inset: 0; }
.cell.sel .fill { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.grid:focus .cell.sel .fill { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.grid:focus .cell.cursor .fill { outline: 1px solid var(--accent); outline-offset: -1px; }
.cell .box {
  position: absolute; inset: -2px; pointer-events: none; z-index: 2;
  border: 0 solid var(--accent);
}
.cell .label {
  position: absolute; left: 12px; top: 0; bottom: 0; z-index: 3;
  display: flex; align-items: center;
  width: calc(100% - 24px);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: clamp(20px, 2.6vh, 28px);
  color: var(--ink, var(--fg));
  pointer-events: none;
}
.cell .label.span { width: calc(200% - 24px); }
.editor {
  position: absolute; z-index: 10;
  background: var(--bg); color: var(--fg);
  border: 3px solid var(--accent); outline: 0;
  padding: 0 10px; font-size: clamp(20px, 2.6vh, 28px);
}

/* ---- footer ---- */
.foot {
  grid-area: foot;
  display: flex; justify-content: space-between; gap: 16px;
  color: var(--muted); font-size: 12px; letter-spacing: .5px;
}
.credit a { color: inherit; }

/* ---- saved-image poster (built off screen) ---- */
.poster-holder { position: fixed; left: -10000px; top: 0; }
.poster {
  width: 540px; padding: 32px 28px 36px;
  background: var(--bg); color: var(--fg);
  display: flex; flex-direction: column;
}
.poster > * { order: 0 !important; margin-bottom: 0; }
.poster h2 { margin-bottom: 10px; }
.poster .p-head { display: flex; align-items: center; gap: 18px; margin-bottom: 26px; }
.poster .badge { width: 72px; height: 72px; min-width: 72px; }
.poster h1 { font-size: 25px; }
.poster .p-date { font-size: 30px; border-bottom: 1px solid var(--fg); margin-top: 4px; }
.poster .priorities { margin-bottom: 24px; }
.poster .prio { height: 46px; }
.poster .p-prio { font-size: 26px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.poster .prio.done .p-prio { text-decoration: line-through; opacity: .5; }
.poster .grid { height: auto; min-height: 0; grid-template-rows: repeat(17, 40px); }
.poster .cell .label { font-size: 24px; }

.exporting .cell .fill { background: none !important; outline: 0 !important; }
.exporting .dump-col.empty::before, .exporting .prio input::placeholder { color: transparent; }

/* ---- phones and narrow windows ---- */
@media (max-width: 860px) {
  #page {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-template-areas: "top" "locked" "left" "right" "foot";
    align-content: start;
    row-gap: 8px;
    padding: 16px;
  }
  /* One column: brain dump, then priorities, then the schedule. */
  .top, .locked, .right, .foot { grid-area: auto; }
  .left { display: contents; }
  .left > h2:nth-of-type(2), .dump { order: 1; }
  .left > h2:first-child, .priorities { order: 2; }
  .right { order: 3; }
  .foot { order: 4; }
  .priorities, .dump { margin-bottom: 18px; }
  .top { gap: 12px; }
  h1 { font-size: 20px; }
  .date-text { font-size: 26px; }
  .wide { display: none; }
  .grid { grid-template-rows: repeat(17, 44px); }
  .cell .label, .editor { font-size: 23px; }
  .dump { grid-template-columns: 1fr; min-height: 0; }
  .dump-divider { height: 1px; margin: 0 10px; }
  .dump-col { min-height: 160px; }
  .hints { display: none; }
}
