/* Duty Hours — mobile-first, 48px touch targets */
:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #17202a;
  --muted: #5f6b7a;
  --accent: #0d47a1;
  --accent-ink: #ffffff;
  --danger: #b00020;
  --line: #d9dee5;
  --radius: 12px;
}
/* OLED dark: true black, used when the system is dark (unless forced light) or when forced dark */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000; --card: #000; --ink: #ececec; --muted: #8a8a8a; --danger: #ff6b81; --line: #262626;
    --header: #000;
  }
}
:root[data-theme="dark"] {
  --bg: #000; --card: #000; --ink: #ececec; --muted: #8a8a8a; --danger: #ff6b81; --line: #262626;
  --header: #000;
}
html { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.4;
}

#app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 8px;
  background: var(--header, var(--accent));
  color: #fff;
  border-bottom: 2px solid var(--accent);
}
#app-header h1 { font-size: 1.15rem; margin: 0; }
.hdr-btn {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 8px;
  background: transparent;
  color: #fff;
  font-size: 0.9rem;
}

main { padding: 12px 12px calc(env(safe-area-inset-bottom, 0px) + 24px); max-width: 900px; margin: 0 auto; }
.screen { display: none; }
.screen.active { display: block; }
#screen-settings { max-width: 560px; margin: 0 auto; }
h2 { font-size: 1.25rem; margin: 8px 0 12px; }
h3 { font-size: 1rem; margin: 4px 0 8px; }

label { display: block; margin: 12px 0; font-weight: 600; }
input[type="text"], input[type="url"], input[type="password"], input[type="month"], input[type="date"],
input[type="time"], select, textarea {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-weight: 400;
}
textarea { resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 0.9rem; }

.btn {
  display: block;
  width: 100%;
  min-height: 48px;
  margin: 10px 0;
  padding: 12px 16px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--accent);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
.btn:active { filter: brightness(0.94); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.secondary { border-color: var(--line); color: var(--ink); }
.btn.big { min-height: 60px; font-size: 1.1rem; }

.chip {
  min-height: 44px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font-size: 0.85rem;
  cursor: pointer;
}

.msg { margin: 10px 0; color: var(--muted); }
.hint { color: var(--muted); font-size: 0.85rem; font-weight: 400; }
.hidden { display: none !important; }

/* ---------- planner ---------- */
.month-row { display: flex; gap: 8px; align-items: center; }
.month-row input { margin: 0; flex: 1; }
.month-row .btn { width: auto; flex: none; margin: 0; padding: 0 18px; font-size: 1.3rem; }

.panel { margin: 12px 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.panel h3 { margin-top: 0; }
.btn.small { width: auto; min-height: 40px; padding: 6px 14px; font-size: 0.9rem; margin: 6px 0; }

.brushes { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 10px; }
.brush.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr)) 2.4em;
  gap: 3px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.head { text-align: center; font-size: 0.75rem; color: var(--muted); }
.cell {
  min-height: 62px;
  padding: 3px 4px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  font-size: 0.68rem;
  line-height: 1.2;
  overflow: hidden;
  cursor: pointer;
}
.cell.blank { background: transparent; border-color: transparent; cursor: default; }
.cell.today { outline: 2px solid var(--accent); outline-offset: 1px; }
.cell.planned { border-style: dashed; border-color: var(--muted); }
.cell.due { border: 2px solid var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--card)); }
.cell.off .name { color: var(--muted); font-weight: 400; }
.cell.logged { border-color: #2e7d32; background: color-mix(in srgb, #2e7d32 14%, var(--card)); }
.cell.logged .name { color: #2e7d32; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 2px; }
.day { font-weight: 700; font-size: 0.8rem; }
.rot { padding: 0 4px; border-radius: 4px; color: #fff; font-size: 0.6rem; font-weight: 700; white-space: nowrap; overflow: hidden; }
.name, .time { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.name { font-weight: 600; }
.time { color: var(--muted); }
.week { align-self: center; text-align: center; font-size: 0.75rem; font-weight: 700; color: var(--muted); }
.week.over { color: var(--danger); }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 10px 0; }
.actions .btn { margin: 0; font-size: 0.9rem; }

details { margin-top: 16px; }
details summary { min-height: 48px; display: flex; align-items: center; font-weight: 600; cursor: pointer; }

/* editable rows (blocks, rotations, weekly, e-value entries) */
.row { display: grid; gap: 6px; align-items: center; margin-bottom: 6px; }
.row input, .row select { margin: 0; min-height: 44px; padding: 6px 8px; font-size: 0.9rem; }
.row .btn { margin: 0; }
.seg, .seg-head { grid-template-columns: 7.4rem 7.4rem minmax(0, 1fr) minmax(0, 1fr) 44px; }
.evrow { grid-template-columns: 7.4rem 7.4rem minmax(0, 1fr) minmax(0, 1fr) auto 44px; }
.seg-head { display: grid; gap: 6px; font-size: 0.75rem; color: var(--muted); }
.weekrow { grid-template-columns: 5em 7.4rem 7.4rem minmax(0, 1fr) 44px; }
.del { padding: 0; }
.type { padding: 8px 0 4px; border-top: 1px solid var(--line); }
.type-head { display: grid; grid-template-columns: 1fr 44px; gap: 6px; margin-bottom: 6px; }
.type-head input { margin: 0; font-weight: 600; }
.preview { font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; }
.pv { padding: 3px 0; border-bottom: 1px solid var(--line); }
.pv.off { color: var(--muted); }
.check-row { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
.check-row input { width: 22px; height: 22px; flex: none; margin-top: 1px; }

@media (max-width: 520px) {
  /* stack activity/task under the times on phones */
  .seg, .evrow { grid-template-columns: 1fr 1fr 44px; }
  .seg-head { display: none; }
  .seg select, .evrow select, .evrow .btn.small { grid-column: span 1; }
  .rotrow { grid-template-columns: 1fr 1fr 44px; }
  .rotrow select { grid-column: 1 / 3; }
  .weekrow { grid-template-columns: 4.5em 1fr 1fr 44px; }
  .weekrow select:last-of-type { grid-column: 1 / 4; }
}

/* ---------- sheets + toast ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: 100%;
  max-width: 720px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
  border-radius: 16px 16px 0 0;
  background: var(--card);
}
.toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  z-index: 60;
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--bg);
}

@media (min-width: 900px) {
  .cell { min-height: 80px; font-size: 0.8rem; }
  .actions { grid-template-columns: repeat(5, 1fr); }
}

/* ---------- Amion: rotation names, block tags, mapping table ---------- */
.tag { display: block; margin-top: 1px; padding: 0 3px; border-radius: 3px; background: color-mix(in srgb, var(--accent) 14%, transparent); font-size: 0.62rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag.acad { background: #fde68a; color: #713f12; font-weight: 700; }
.rotname { padding: 4px 6px; border-radius: 6px; color: #fff; font-size: 0.8rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rotrow { grid-template-columns: minmax(6em, 0.8fr) minmax(8.5em, 1fr) minmax(8.5em, 1fr) minmax(0, 1.2fr) 44px; }
.maprow { grid-template-columns: minmax(0, 0.7fr) minmax(0, 1.3fr) minmax(0, 1fr); }
.sessrow { grid-template-columns: 3em 8.5em 8.5em; }
.mapkey { font-weight: 700; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 520px) {
  .rotrow { grid-template-columns: 1fr 1fr 44px; }
  .rotrow .rotname { grid-column: 1 / 4; }
  .rotrow select { grid-column: 1 / 3; }
  .maprow { grid-template-columns: 1fr 1fr; }
  .maprow .mapkey { grid-column: 1 / 3; }
}

/* ---------- fun mode ---------- */
.hdr-actions { display: flex; gap: 6px; }
#fun.active { background: rgba(255, 255, 255, 0.25); }
.fun-canvas { position: fixed; inset: 0; z-index: 40; pointer-events: none; }
/* drifting rainbow; cards keep their own background so the calendar stays readable */
body.fun {
  background: linear-gradient(120deg, #ff9aa2, #ffb347, #fff275, #9ef01a, #6ee7f9, #a78bfa, #f472b6, #ff9aa2);
  background-size: 400% 400%;
  background-attachment: fixed;
  animation: rainbow 18s linear infinite;
}
@keyframes rainbow { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }
body.fun #app-header { background: linear-gradient(90deg, #ff4fa3, #ffb347, #9ef01a, #00bbf9, #9b5de5, #ff4fa3); background-size: 300% 100%; animation: rainbow 8s linear infinite; }
body.fun .cell.due { border-color: #ff4fa3; }
@media (prefers-reduced-motion: reduce) { body.fun, body.fun #app-header { animation: none; } }
.tag.nd { background: transparent; border: 1px dashed var(--line); color: var(--muted); }

.sub { color: var(--muted); font-size: 0.85rem; min-height: 1em; }
.color-row { display: flex; align-items: center; gap: 12px; }
.color-row input, .rotname input { width: 44px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }
.rotname { display: flex; align-items: center; gap: 6px; margin: 0; padding: 0; color: var(--ink); background: none !important; font-weight: 700; }
.rotname input { width: 30px; height: 28px; flex: none; }

/* time fields: room for "12:30 PM" plus the native clock icon, without overlap */
input[type="time"] { min-width: 7.6em; padding-right: 4px; font-variant-numeric: tabular-nums; }
input[type="time"]::-webkit-calendar-picker-indicator { margin-left: 2px; padding: 0; }

/* ---------- welcome ---------- */
.welcome { max-width: 420px; margin: 6vh auto 0; text-align: center; }
.welcome label { text-align: left; }
.welcome .logo { font-size: 3rem; }
.welcome h2 { margin: 4px 0 12px; font-size: 1.6rem; }
.steps { display: flex; justify-content: center; gap: 8px; padding: 0; margin: 0 0 8px; list-style: none; counter-reset: s; }
.steps li { counter-increment: s; padding: 4px 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 0.85rem; }
.steps li::before { content: counter(s) " · "; }
.steps li.on { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.theme-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.theme-opt { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 6px; border: 2px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.theme-opt[aria-checked="true"] { border-color: var(--accent); }
.theme-opt .sw { width: 100%; height: 44px; border-radius: 8px; border: 1px solid var(--line); }
.sw.lt { background: #f6f7f9; }
.sw.dk { background: #000; }
.sw.sys { background: linear-gradient(135deg, #f6f7f9 50%, #000 50%); }
.accent-pick { display: flex; justify-content: center; align-items: center; gap: 10px; margin: 12px 0 4px; }
.accent-pick .dot { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.accent-pick .dot[aria-checked="true"] { border-color: var(--ink); }
.accent-pick input { width: 40px; height: 36px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: none; }
