/* Habi printable habit tracker: the designer's own styles.
   Colours, type and the focus ring come from /css/styles.css. The one bright
   thing on the page is the sheet: white paper on the dark surface. */

.phd-app {
  /* the edge of every control: 3.6:1 against the surface (WCAG 1.4.11) */
  --phd-edge: rgba(255, 255, 255, 0.38);
}

.phd-app {
  background: var(--surface-dark, #0e0f11);
  container-type: inline-size;
  container-name: phd;
}
/* "hidden" always wins inside the designer. Several controls here set their own
   display (flex rows of pills, switches), which silently overrode the hidden
   attribute: "Week starts on" stayed on screen on sheets where it changes nothing. */
.phd-app [hidden] { display: none !important; }

.phd-form {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  color: var(--text-body);
  font-family: 'Inter Display', sans-serif;
  font-size: 15px;
}

/* ---- top bar: help toggle and the four layouts ---- */
.phd-topbar {
  flex: none;
  gap: 12px;
  padding: 14px 20px 12px;
  flex-wrap: wrap;
}
.phd-seg {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}
.phd-seg input,
.phd-chips input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}
.phd-seg label,
.phd-chips label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--phd-edge);
  border-radius: 40px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.phd-seg label:hover,
.phd-chips label:hover { background: var(--bg-hover); color: var(--text-primary); }
.phd-seg input:checked + label,
.phd-chips input:checked + label {
  background: #fff;
  border-color: #fff;
  color: #0e0f11;
}
.phd-seg input:focus-visible + label,
.phd-chips input:focus-visible + label {
  outline: var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
}
.phd-seg-small label { min-height: 40px; padding: 0 14px; }

/* ---- top bar: help on the left; layout, language and Start over on the right ---- */
.phd-top-left { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.phd-top-right { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 8px; min-width: 0; margin-left: auto; }
/* Layout is five pills while the bar has room and one menu when it does not.
   Both drive the same choice; only one is ever on screen or in the tab order. */
.phd-dd[data-key="layout"] { display: none; }
@container phd (max-width: 880px) {
  .phd-layout-pills { display: none; }
  .phd-dd[data-key="layout"] { display: block; }
}
.phd-dd { position: relative; }
.phd-dd-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  box-sizing: border-box;
  border: 1px solid var(--phd-edge);
  border-radius: 40px;
  background: var(--bg-hover);
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.phd-dd-trigger:hover { background: var(--bg-hover-strong); }
.phd-dd-trigger:focus-visible { outline: var(--focus-ring); outline-offset: var(--focus-ring-offset); }
.phd-dd-arrow { font-size: 14px; transition: transform 0.2s; }
.phd-dd.open .phd-dd-arrow { transform: rotate(180deg); }
.phd-dd-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 200px;
  max-height: min(70vh, 420px);
  overflow-y: auto;
  margin: 0;
  padding: 12px;
  list-style: none;
  border-radius: 20px;
  background: rgba(30, 30, 30, 0.97);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1), 0 24px 48px -12px rgba(0, 0, 0, 0.8);
}
.phd-dd-menu li {
  padding: 12px 20px;
  border-radius: 40px;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
  cursor: pointer;
}
.phd-dd-menu li.is-active { background: var(--bg-hover); }
/* the chosen one is marked by a tick as well as by its fill */
.phd-dd-menu li[aria-selected="true"] { background: var(--bg-hover-strong); }
.phd-dd-menu li[aria-selected="true"]::before { content: "\2713\00a0"; }
.phd-top-reset { gap: 8px; color: var(--text-secondary); font-weight: 500; padding: 0 16px; }
.phd-top-reset svg { flex: none; }
/* On a phone the bar keeps to one row: "Help", the two menus, and Start over as its icon.
   The full names stay in place for screen readers. */
@container phd (max-width: 520px) {
  #btn-help { padding: 0 16px; min-height: 44px; }
  .phd-help-verb { display: none; }
  .phd-top-reset { width: 44px; padding: 0; }
  .phd-reset-text { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
}

/* ---- work area: controls beside the sheet ---- */
.phd-work {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  border-top: 1px solid var(--border-subtle);
}
.phd-controls {
  grid-column: 1;
  grid-row: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 20px 28px;
  border-right: 1px solid var(--border-subtle);
}
.phd-stage {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 24px 28px 16px;
  /* in a short window the sheet keeps its minimum height and this column scrolls */
  overflow-y: auto;
}
.phd-paper-area {
  flex: 1 0 auto;
  height: 0;
  min-height: 250px;
  container-type: size;
  display: flex;
  align-items: center;
  justify-content: center;
}
.phd-paper {
  --phd-ar: 1.2941;
  width: min(100cqw, calc(100cqh * var(--phd-ar)));
  aspect-ratio: var(--phd-ar);
  background: #fff;
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 28px 60px -18px rgba(0, 0, 0, 0.85);
  animation: phd-settle 0.45s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.phd-paper svg { display: block; width: 100%; height: 100%; }
@keyframes phd-settle {
  from { opacity: 0; transform: translateY(14px) rotate(-0.6deg); }
  to { opacity: 1; transform: none; }
}
.phd-pager {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding-top: 12px;
  color: var(--text-secondary);
  font-size: 14px;
}
.phd-pager[hidden] { display: none; }

/* ---- designs: a strip of real thumbnails under the sheet ---- */
.phd-designs { flex: none; padding-top: 14px; min-width: 0; }
.phd-designs-title {
  margin: 0 0 8px;
  color: var(--text-secondary);
  font-family: 'Inter Display', sans-serif;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: 0;
}
.phd-design-list {
  /* room for the thumbnails is held before the script draws them, so nothing jumps */
  min-height: 126px;
  box-sizing: border-box;
  display: flex;
  gap: 10px;
  margin: 0;
  padding: 4px 4px 10px;
  list-style: none;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}
.phd-design-list li { flex: none; scroll-snap-align: start; }
.phd-design {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.phd-design:hover { background: var(--bg-hover); color: var(--text-primary); }
.phd-design:focus-visible { outline: var(--focus-ring); outline-offset: 1px; }
.phd-design[aria-current="true"] { border-color: #fff; color: var(--text-primary); }
.phd-design-thumb {
  display: block;
  height: 72px;
  border-radius: 2px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.14);
}
.phd-design-thumb svg { display: block; width: 100%; height: 100%; }
.phd-design-name { white-space: nowrap; }

/* ---- control groups ---- */
.phd-group {
  margin: 0;
  padding: 18px 0;
  border: 0;
  border-bottom: 1px solid var(--border-subtle);
  min-width: 0;
}
.phd-group[hidden] { display: none; }
.phd-group > legend,
.phd-more > summary {
  padding: 0;
  margin-bottom: 12px;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 600;
}
/* The heading is a plain block with its gap as padding. It used to be floated
   and cleared by the element after it; when that element was hidden (the habit
   list, once "Blank rows" is on) the next control slid out beside the heading. */
.phd-group > legend { display: block; width: 100%; margin: 0; padding: 0 0 12px; }
.phd-sub {
  margin: 16px 0 8px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
}
.phd-sub:first-child { margin-top: 0; }
.phd-hint {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.45;
}
.phd-hint[hidden] { display: none; }
.phd-row { display: flex; gap: 10px; }
.phd-row > * { flex: 1; min-width: 0; }
.phd-field { display: block; }
.phd-field[hidden] { display: none; }
.phd-field > span {
  display: block;
  margin-bottom: 6px;
  color: var(--text-secondary);
  font-size: 13px;
}
.phd-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  box-sizing: border-box;
  background: var(--bg-subtle);
  border: 1px solid var(--phd-edge);
  border-radius: 10px;
  color: var(--text-primary);
  font: inherit;
  font-size: 15px;
}
.phd-input::placeholder { color: var(--text-muted); }
.phd-input:disabled { opacity: 0.45; }
select.phd-input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%23ffffff' stroke-opacity='.7' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
}
select.phd-input option { background: #1c1d21; color: #fff; }
.phd-input:focus-visible,
.phd-switch input:focus-visible,
.phd-icon:focus-visible,
.phd-btn:focus-visible,
.phd-link:focus-visible,
.phd-more > summary:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
}

/* a real checkbox, drawn as a switch: the knob moves, so state never
   depends on colour alone */
.phd-switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 44px;
  color: var(--text-body);
  cursor: pointer;
}
.phd-switch[hidden] { display: none; }
.phd-switch input {
  flex: none;
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 44px;
  height: 26px;
  margin: 0;
  border: 1px solid var(--phd-edge);
  border-radius: 20px;
  background: var(--bg-subtle);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.phd-switch input::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.72);
  transition: transform 0.15s, background 0.15s;
}
.phd-switch input:checked { background: #6f4ef0; border-color: #a58bff; }
.phd-switch input:checked::before { transform: translateX(18px); background: #fff; }
.phd-switch input:disabled { opacity: 0.4; cursor: default; }

/* ---- habit list ---- */
.phd-habit-editor[hidden] { display: none; }
.phd-habits { list-style: none; margin: 0 0 10px; padding: 0; }
.phd-habit { display: flex; align-items: center; gap: 4px; margin-bottom: 6px; }
.phd-habit .phd-input { flex: 1; min-width: 0; }
.phd-icon {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}
.phd-icon:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }
.phd-icon:disabled { opacity: 0.28; cursor: default; }
.phd-pager .phd-icon { width: 44px; border: 1px solid var(--phd-edge); }
@media (pointer: coarse) { .phd-icon { width: 44px; } }

/* ---- colour chips: a named radio each ---- */
.phd-chips { position: relative; display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; border: 0; }
.phd-chips label { min-height: 40px; padding: 0 12px 0 8px; font-weight: 500; }
.phd-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--dot, #fff);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}
.phd-chips input:checked + label .phd-dot { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25); }
.phd-dot-ink { background: #fff; box-shadow: inset 0 0 0 2px #000, 0 0 0 1px rgba(255, 255, 255, 0.5); }
.phd-group > fieldset { margin-bottom: 14px; }
.phd-group > fieldset > legend { margin: 0; padding: 0 0 8px; }
.phd-swatch {
  display: block;
  width: 100%;
  height: 44px;
  padding: 4px;
  box-sizing: border-box;
  border: 1px solid var(--phd-edge);
  border-radius: 10px;
  background: var(--bg-subtle);
  cursor: pointer;
}
.phd-swatch:focus-visible { outline: var(--focus-ring); outline-offset: var(--focus-ring-offset); }

/* ---- more options ---- */
.phd-more { padding: 18px 0 6px; border-bottom: 1px solid var(--border-subtle); }
.phd-more > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  margin-bottom: 0;
  list-style: none;
  cursor: pointer;
  border-radius: 8px;
}
.phd-more > summary::-webkit-details-marker { display: none; }
.phd-more > summary::after {
  content: "";
  width: 9px;
  height: 9px;
  margin-right: 6px;
  border-right: 1.6px solid var(--text-secondary);
  border-bottom: 1.6px solid var(--text-secondary);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform 0.15s;
}
.phd-more[open] > summary::after { transform: rotate(-135deg) translate(-2px, -2px); }
.phd-more-body { padding: 8px 0 14px; }
.phd-more-body > fieldset { margin-bottom: 18px; }
.phd-more-body > fieldset > legend { margin: 0; padding: 0 0 8px; }

/* ---- buttons ---- */
.phd-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 20px;
  border: 1px solid var(--phd-edge);
  border-radius: 40px;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.phd-btn:hover:not(:disabled) { background: var(--bg-hover); }
.phd-btn:disabled { opacity: 0.5; cursor: default; }
.phd-btn[hidden] { display: none; }
.phd-btn-primary { background: #fff; border-color: #fff; color: #0e0f11; }
.phd-btn-primary:hover:not(:disabled) { background: #e9e6ff; }
.phd-btn-quiet {
  width: 100%;
  margin-top: 4px;
  border-style: dashed;
  color: var(--text-secondary);
  font-weight: 500;
  white-space: normal;
  text-align: center;
  line-height: 1.3;
  padding: 8px 16px;
}
.phd-link {
  margin-top: 16px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-secondary);
  font: inherit;
  font-size: 14px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.phd-link:hover { color: var(--text-primary); }

/* ---- bottom bar: what the sheet is, and the two ways out ---- */
.phd-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-dark, #0e0f11);
}
.phd-bar-text { min-width: 0; }
.phd-summary { margin: 0; color: var(--text-secondary); font-size: 13px; line-height: 1.4; }
.phd-warnings,
.phd-status { margin: 2px 0 0; font-size: 13px; line-height: 1.4; }
.phd-warnings { color: #ffc46b; }
.phd-warnings[hidden] { display: none; }
.phd-status { color: var(--text-primary); }
.phd-status:empty { display: none; }
.phd-bar-actions { flex: none; display: flex; gap: 8px; }

/* ---- narrow: the sheet on top, controls underneath, actions pinned ---- */
@container phd (max-width: 720px) {
  .phd-work { display: flex; flex-direction: column; overflow-y: auto; }
  .phd-stage { order: -1; flex: none; padding: 16px 16px 12px; overflow: visible; }
  .phd-paper-area { container-type: inline-size; flex: none; height: auto; min-height: 0; }
  .phd-paper { width: 100%; }
  .phd-design-thumb { height: 64px; }
  .phd-design-list { min-height: 118px; }
  .phd-controls { overflow: visible; border-right: 0; padding: 0 16px 24px; }
  .phd-topbar { padding: 12px 16px 10px; gap: 8px; }
  .phd-dd-trigger { padding: 0 14px; }
  .phd-bar { padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .phd-summary { display: none; }
  .phd-bar-actions { flex: 1; }
  .phd-bar-actions .phd-btn { flex: 1; }
  .phd-bar-text:has(.phd-warnings[hidden]):has(.phd-status:empty) { display: none; }
  .phd-bar { flex-wrap: wrap; }
}

/* ---- ready-made sheets in the article ---- */
.tool-page ul.phd-ready {
  list-style: none;
  margin: 0 0 28px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px 10px;
}
.phd-ready li { margin: 0; padding: 0; }
.phd-ready li::before { content: none; }
/* the landscape sheet gets the full row, the three upright ones share the next */
.phd-ready li:first-child { grid-column: 1 / -1; }
/* a layout page's sheets are all one shape, so they sit in an even grid */
.tool-page ul.phd-ready.phd-ready-wide { grid-template-columns: 1fr 1fr; }
.tool-page ul.phd-ready.phd-ready-wide li:first-child,
.tool-page ul.phd-ready.phd-ready-tall li:first-child { grid-column: auto; }
.phd-ready img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 3px;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.phd-ready strong { display: block; margin: 8px 0 2px; color: var(--text-primary); font-size: 14px; }
.phd-ready span { color: var(--text-secondary); font-size: 14px; }

/* ---- in the guide: the comparison table (scrolls inside itself if the column is too narrow) ---- */
.phd-table { margin: 0 0 28px; overflow-x: auto; }
.phd-table table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 1.45; }
.phd-table caption { caption-side: bottom; padding-top: 8px; color: var(--text-muted); font-size: 13px; text-align: left; }
.phd-table th, .phd-table td { padding: 10px 10px 10px 0; border-bottom: 1px solid var(--border-default); text-align: left; vertical-align: top; }
.phd-table thead th { color: var(--text-secondary); font-weight: 600; }
.phd-table tbody th { color: var(--text-primary); font-weight: 600; white-space: nowrap; }
.phd-table td { color: var(--text-body); }

/* ---- in the guide: the page trail and the gallery of looks ---- */
.phd-crumbs { margin: 0 0 10px; color: var(--text-muted); font-size: 14px; }
.phd-crumbs a { color: var(--text-secondary); }
.tool-page ul.phd-gallery { list-style: none; margin: 0 0 28px; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 14px 10px; }
.phd-gallery li { margin: 0; padding: 0; }
.phd-gallery li::before { content: none; }
.phd-gallery button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-secondary);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.phd-gallery button:hover { color: var(--text-primary); }
.phd-gallery button:focus-visible { outline: var(--focus-ring); outline-offset: 3px; border-radius: 3px; }
.phd-gallery img { display: block; width: 100%; height: auto; margin-bottom: 6px; border-radius: 3px; background: #fff; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08); }

/* ---- printing: only the sheets, edge to edge ---- */
#phd-print-root { display: none; }
@media print {
  html, body { background: #fff !important; margin: 0 !important; padding: 0 !important; }
  body > *:not(#phd-print-root) { display: none !important; }
  #phd-print-root { display: block; }
  #phd-print-root svg {
    display: block;
    width: 100vw;
    height: 100vh;
    break-after: page;
    page-break-after: always;
  }
  #phd-print-root svg:last-child { break-after: auto; page-break-after: auto; }
}
