/* Day content editor (js/day.js). Two parts:
 *   dy-*  the editor: list, episode card, screens, block editor, simulator;
 *   dp-*  the phone renderer shared by the preview and the simulator: the
 *         402 x 874 Figma frame, scaled by js/day.js.
 *
 * Colours, type and spacing come from console.css's tokens (the iOS
 * DesignSystem). The veils and the Day glow are the DS's unbound stops
 * (Veil.swift, DayAtmosphere.swift), written as color-mix over the tokens;
 * the glow's candle is the one value with no token (DayAtmosphere.candle).
 * Approximate on purpose: the preview shows the words, the emphasis and
 * the art, not pixels.
 */

/* ------------------------------------------------------------ editor */

.dy-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s12);
  padding: var(--s48) 0;
  animation: console-fade var(--dur-step) ease;
}

/* The list: a Day card, the DayAtmosphere Light glow over its paper (the
 * candle top right, Orange/400 bottom left) and the sun before its title. */
.dy-list {
  background:
    radial-gradient(70% 140% at 100% 0%, var(--atmos-day-candle) 0%, transparent 90%),
    radial-gradient(60% 120% at 0% 100%, rgba(255, 134, 86, 0.06) 0%, transparent 100%),
    var(--surface-raised);
  animation: console-enter var(--dur-enter) var(--ease);
}

.dy-list .card-title,
.dy-head-title {
  display: flex;
  align-items: center;
  gap: var(--s8);
}

.dy-list .card-title::before,
.dy-head-title::before {
  content: "";
  flex: none;
  width: 22px;
  height: 22px;
  background: var(--orange-500);
  -webkit-mask: url("/icons/sun.svg") center / contain no-repeat;
  mask: url("/icons/sun.svg") center / contain no-repeat;
}

.dy-head-title::before {
  align-self: center;
}

.dy-head {
  display: flex;
  align-items: center;
  gap: var(--s12);
  flex-wrap: wrap;
  margin-bottom: var(--s16);
}

.dy-head-title {
  display: flex;
  align-items: baseline;
  gap: var(--s12);
  min-width: 0;
}

.dy-head .btn-quiet.ic-arrow-left {
  margin-left: calc(-1 * var(--s12));
}

.dy-day {
  font: 400 23px/32px var(--font-serif);
  letter-spacing: -0.01em;
}

.dy-notices {
  display: flex;
  flex-direction: column;
  gap: var(--s8);
  margin-bottom: var(--s16);
}

.dy-notices:empty {
  display: none;
}

.dy-ok {
  color: var(--teal-500);
  background: var(--teal-050);
  border-color: var(--teal-100);
}

.dy-problems-head {
  font-weight: 600;
}

.dy-problems ul {
  margin: var(--s8) 0 0;
  padding-left: var(--s20);
}

.dy-link,
.dy-link:hover {
  border: none;
  background: none;
  padding: 0;
  border-radius: 0;
  font: inherit;
  font-weight: 600;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.dy-grid {
  display: grid;
  gap: var(--s16);
  align-items: start;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr) 300px;
  grid-template-areas: "side main preview";
}

.dy-side {
  grid-area: side;
  display: flex;
  flex-direction: column;
  gap: var(--s16);
  min-width: 0;
}

.dy-main {
  grid-area: main;
  min-width: 0;
}

/* Stretched over the row so the card inside can stick. */
.dy-preview {
  grid-area: preview;
  align-self: stretch;
}

.dy-preview .card {
  padding: var(--s16);
}

.dy-sticky {
  position: sticky;
  top: 76px;
}

.dy-phone-holder {
  display: flex;
  justify-content: center;
}

@media (max-width: 1180px) {
  .dy-grid {
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-areas: "side preview" "main preview";
  }
}

@media (max-width: 820px) {
  .dy-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "side" "main" "preview";
  }

  .dy-sticky {
    position: static;
  }
}

/* ---- list */

.dy-table-wrap {
  overflow-x: auto;
}

.dy-table {
  width: 100%;
  border-collapse: collapse;
}

.dy-table th {
  text-align: left;
  font: 600 11px/16px var(--font-sans);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  padding: var(--s8) var(--s12);
  border-bottom: 1px solid var(--border-default);
  white-space: nowrap;
}

.dy-table td {
  padding: var(--s12);
  border-bottom: 1px solid var(--neutral-100-soft);
  vertical-align: middle;
}

.dy-row {
  cursor: pointer;
}

.dy-row td {
  transition: background-color var(--dur-quick) ease;
}

.dy-row:hover td {
  background: color-mix(in srgb, var(--orange-050) 70%, transparent);
}


.dy-row:focus-visible {
  outline: 2px solid var(--orange-500);
  outline-offset: -2px;
}

.dy-num {
  width: 48px;
  font-size: 19px;
  color: var(--text-secondary);
}

.dy-title-cell {
  font-size: 16px;
}

.dy-right {
  text-align: right;
}

.dy-when {
  font-size: 13px;
  white-space: nowrap;
}

/* ---- screens */

.dy-screens {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dy-screen {
  display: grid;
  grid-template-columns: 20px auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--s8);
  padding: 6px var(--s8);
  border: 1px solid transparent;
  border-radius: var(--r12);
  cursor: pointer;
  transition: background-color var(--dur-quick) ease,
    border-color var(--dur-quick) ease;
}

.dy-screen:hover {
  background: var(--tint-05);
}

.dy-screen.is-selected {
  background: var(--orange-050);
  border-color: var(--orange-100);
}

.dy-idx {
  font: 600 13px/18px var(--font-sans);
  color: var(--text-tertiary);
  text-align: right;
}

.dy-screen.has-error .dy-idx {
  color: var(--console-error-text);
}

.dy-screen.has-error .dy-sum::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--console-error-text);
  vertical-align: 1px;
}

.dy-type {
  font: 600 11px/16px var(--font-sans);
  letter-spacing: 0.01em;
  border-radius: var(--r999);
  padding: 2px var(--s8);
  background: var(--surface-highlight);
  color: var(--text-secondary);
}

.dy-type-title,
.dy-type-art {
  background: var(--neutral-900-charcoal);
  color: var(--neutral-050-paper);
}

.dy-type-question {
  background: var(--orange-050);
  color: var(--orange-500);
}

.dy-sum {
  font: 400 14px/20px var(--font-serif);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dy-ops {
  display: flex;
  gap: 2px;
}

/* A screen's operations show on the selected screen only, so the other
 * rows keep their width for the summary. */
.dy-screen:not(.is-selected) .dy-ops {
  display: none;
}

.dy-op {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--r8);
  background: transparent;
  color: var(--text-secondary);
  font: 600 14px/1 var(--font-sans);
}

.dy-op.ic::before {
  width: 15px;
  height: 15px;
}

.dy-op:hover {
  background: var(--white-100);
  border-color: var(--border-default);
}

.dy-op:disabled:hover {
  background: transparent;
  border-color: transparent;
}

/* ---- screen card: image, blocks, marks */

.dy-main > .card {
  gap: var(--s20);
}

.dy-image {
  display: flex;
  gap: var(--s16);
  align-items: flex-start;
}

.dy-thumb {
  flex: none;
  width: 72px;
  height: 156px;
  object-fit: cover;
  border-radius: var(--r12);
  background: var(--neutral-900-charcoal);
}

.dy-thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font: 600 11px/16px var(--font-sans);
  color: var(--neutral-400-quiet);
}

.dy-image-side {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--s8);
  min-width: 0;
}

.dy-block {
  display: flex;
  flex-direction: column;
  gap: var(--s12);
  padding: var(--s16);
  border: 1px solid var(--border-default);
  border-radius: var(--r16);
  background: var(--white-100);
}

.dy-block-head {
  display: flex;
  align-items: center;
  gap: var(--s8);
}

.dy-block-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s12);
}

.dy-block-text {
  font: 400 17px/26px var(--font-serif);
  min-height: 88px;
}

.dy-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s4) var(--s8);
}

.dy-tool-regular,
.dy-tool-italic,
.dy-tool-emphasis {
  font-family: var(--font-serif);
  font-size: 14px;
}

.dy-tool-regular {
  font-weight: 400;
}

.dy-tool-italic {
  font-weight: 400;
  font-style: italic;
}

.dy-tool-emphasis {
  font-weight: 600;
}

.dy-tool-ink-accent {
  color: var(--orange-500);
}

.dy-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s8);
}

.dy-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s8);
  max-width: 100%;
  padding: 2px 4px 2px 10px;
  border: 1px solid var(--border-default);
  border-radius: var(--r999);
  background: var(--surface-soft);
  font: 400 13px/18px var(--font-sans);
  cursor: pointer;
}

.dy-chip {
  transition: border-color var(--dur-quick) ease;
}

.dy-chip:hover {
  border-color: var(--neutral-300-mist);
}

.dy-chip > span:first-child {
  min-width: 0;
  font: 400 14px/20px var(--font-serif);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dy-chip .dy-chip-emphasis {
  font-weight: 600;
}

.dy-chip .dy-chip-italic {
  font-style: italic;
}

.dy-chip-ink-accent {
  color: var(--orange-500);
}

.dy-chip-kind {
  font: 600 11px/16px var(--font-sans);
  color: var(--text-tertiary);
  white-space: nowrap;
}

.dy-chip-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  font: 400 15px/1 var(--font-sans);
  color: var(--text-tertiary);
}

.dy-chip-x.ic::before {
  width: 12px;
  height: 12px;
}

.dy-chip-x:hover {
  background: var(--tint-10);
  color: var(--text-primary);
}

.dy-errs {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dy-err {
  font: 600 13px/18px var(--font-sans);
  color: var(--console-error-text);
}

/* ---- simulator */

.dy-sim {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s16);
  background: var(--charcoal-a60);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: console-fade var(--dur-step) ease;
}

.dy-sim:focus {
  outline: none;
}

/* A fixed width (shared by the Night simulator), so a changing footer
 * never reflows the dialog under the cursor; it shrinks to fit a smaller
 * screen and the footer wraps inside it. */
.dy-sim-panel {
  display: flex;
  flex-direction: column;
  gap: var(--s16);
  width: 880px;
  max-width: 100%;
  max-height: 100%;
  overflow: auto;
  padding: var(--s20) var(--s24);
  border-radius: var(--r24);
  background:
    radial-gradient(60% 50% at 100% 0%, var(--atmos-day-candle) 0%, transparent 90%),
    var(--surface-raised);
  box-shadow: var(--shadow-large), 0 24px 64px var(--charcoal-a15);
}

/* The screen change: the next page comes in from the right, the previous
 * from the left, fading (Reduced motion: the fade only). */
.dp-step-next {
  animation: dp-step-next var(--dur-step) var(--ease);
}

.dp-step-back {
  animation: dp-step-back var(--dur-step) var(--ease);
}

@keyframes dp-step-next {
  from {
    opacity: 0;
    transform: translateX(var(--slide));
  }
}

@keyframes dp-step-back {
  from {
    opacity: 0;
    transform: translateX(calc(-1 * var(--slide)));
  }
}

.dy-sim-head,
.dy-sim-foot {
  display: flex;
  align-items: center;
  gap: var(--s16);
  flex-wrap: wrap;
}

.dy-sim-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s24);
}

.dy-sim-nav {
  min-width: 96px;
}

@media (max-width: 640px) {
  .dy-sim-stage {
    gap: var(--s8);
  }

  .dy-sim-nav {
    min-width: 0;
  }
}

/* ------------------------------------------------------ phone (dp-*) */

.dp-phone {
  /* DayAtmosphere.candle: the glow's one stop without a DS token. */
  --dp-candle: #BA966B;
  --dp-charcoal: var(--neutral-900-charcoal);
  --dp-paper: var(--neutral-050-paper);
  position: relative;
  flex: none;
  overflow: hidden;
  background: var(--dp-charcoal);
  box-shadow: 0 0 0 1px var(--charcoal-a10), 0 12px 32px var(--charcoal-a15);
}

.dp-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 402px;
  height: 874px;
  overflow: hidden;
  transform-origin: 0 0;
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

/* ---- art surface (title, art) */

.dp-surface-art {
  background: var(--dp-charcoal);
  color: var(--dp-paper);
}

.dp-ground {
  position: absolute;
  inset: 0;
}

.dp-ground img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

/* Veil · Reader: 0.41 at 0% to 0 at 20%; 0 at 45%, 0.71 at 72%, 0.83. */
.dp-veil-reader {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to bottom,
      color-mix(in srgb, var(--dp-charcoal) 41%, transparent) 0%,
      transparent 20%),
    linear-gradient(to bottom,
      transparent 45%,
      color-mix(in srgb, var(--dp-charcoal) 71%, transparent) 72%,
      color-mix(in srgb, var(--dp-charcoal) 83%, transparent) 100%);
}

/* Veil · Reader title: 0 at 35%, 0.55 at 55%, 0.80 at 75%, 0.85. */
.dp-veil-title {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom,
    transparent 35%,
    color-mix(in srgb, var(--dp-charcoal) 55%, transparent) 55%,
    color-mix(in srgb, var(--dp-charcoal) 80%, transparent) 75%,
    color-mix(in srgb, var(--dp-charcoal) 85%, transparent) 100%);
}

/* The text block: 24 margins, its bottom 150 above the screen bottom. */
.dp-bottom {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 150px;
}

.dp-title-group {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Story / Header (Large): Sans/16 Kicker. */
.dp-story {
  display: flex;
  align-items: center;
  gap: 8px;
  font: 600 16px/24px var(--font-sans);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
}

.dp-story-day {
  color: var(--neutral-150-action);
}

.dp-story-rule {
  flex: none;
  width: 1px;
  height: 14px;
  background: color-mix(in srgb, var(--dp-paper) 30%, transparent);
}

.dp-story-ep {
  color: color-mix(in srgb, var(--dp-paper) 70%, transparent);
  overflow: hidden;
  text-overflow: ellipsis;
}

.dp-title {
  font: 600 47px/52px var(--font-serif);
  letter-spacing: -0.03em;
  color: var(--dp-paper);
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

/* ---- paper surface (glow, question, crisis, ending) with the Day glow */

.dp-surface-paper {
  color: var(--dp-charcoal);
}

.dp-atmos {
  background:
    radial-gradient(304.55px 437px at 353.27px 314.64px,
      color-mix(in srgb, var(--dp-candle) 14%, transparent) 0%,
      transparent 90%),
    radial-gradient(319.05px 393.69px at 0 779.51px,
      color-mix(in srgb, var(--orange-400) 6%, transparent) 0%,
      transparent 100%),
    var(--dp-paper);
}

.dp-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 24px;
}

.dp-glow {
  gap: 48px;
}

/* ---- blocks: style, ink, marks, ref */

.dp-block {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.dp-text {
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.dp-b-statement47 .dp-text {
  font: 600 47px/52px var(--font-serif);
  letter-spacing: -0.03em;
}

.dp-b-statement39 .dp-text {
  font: 600 39px/44px var(--font-serif);
  letter-spacing: -0.02em;
}

.dp-b-statement33 .dp-text {
  font: 600 33px/40px var(--font-serif);
  letter-spacing: -0.02em;
}

.dp-b-body .dp-text {
  font: 400 27px/34px var(--font-serif);
  letter-spacing: -0.01em;
}

.dp-b-bodyItalic .dp-text {
  font: italic 400 27px/34px var(--font-serif);
  letter-spacing: -0.01em;
}

.dp-m-regular {
  font-style: normal;
  font-weight: 400;
}

.dp-m-italic {
  font-style: italic;
  font-weight: 400;
}

/* Upright SemiBold, even inside italic. */
.dp-m-emphasis {
  font-style: normal;
  font-weight: 600;
}

.dp-surface-art .dp-ink-primary {
  color: var(--dp-paper);
}

.dp-surface-paper .dp-ink-primary {
  color: var(--dp-charcoal);
}

.dp-ink-accent {
  color: var(--orange-500);
}

.dp-ref {
  max-width: 342px;
  font: 400 19px/28px var(--font-sans);
}

.dp-surface-art .dp-ref {
  color: var(--neutral-150-action);
}

.dp-surface-paper .dp-ref {
  color: var(--neutral-600-secondary);
}

.dp-empty {
  display: inline-block;
  padding: 8px 16px;
  border: 2px dashed currentColor;
  border-radius: 12px;
  font: 400 19px/28px var(--font-sans);
  letter-spacing: 0;
  opacity: 0.45;
}

/* ---- question */

.dp-question {
  gap: 24px;
}

.dp-prompt {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.dp-q-text {
  font: italic 600 23px/32px var(--font-serif);
  letter-spacing: -0.01em;
  color: var(--orange-500);
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.dp-q-ref {
  max-width: 342px;
  font: 400 16px/24px var(--font-sans);
  color: var(--neutral-600-secondary);
}

/* Field / Write, Flow=Day: 184 tall, Tint/05, R16, Space/16 inside. */
.dp-field {
  display: block;
  width: 100%;
  height: 184px;
  min-height: 184px;
  padding: 16px;
  border: none;
  border-radius: 16px;
  background: var(--tint-05);
  font: 400 16px/24px var(--font-sans);
  color: var(--dp-charcoal);
  resize: none;
}

.dp-placeholder,
.dp-field-input::placeholder {
  color: var(--neutral-500-muted);
}

.dp-field-input:focus {
  border: none;
  box-shadow: inset 0 0 0 2px var(--orange-100);
}

/* ---- chrome: page pill, swipe hint */

.dp-pill {
  position: absolute;
  top: 58px;
  left: 50%;
  width: 84px;
  height: 44px;
  margin-left: -42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font: 600 16px/24px var(--font-sans);
  white-space: pre;
}

.dp-surface-art .dp-pill {
  background: color-mix(in srgb, var(--dp-paper) 30%, transparent);
}

.dp-surface-art .dp-pill-n {
  color: var(--dp-paper);
}

.dp-surface-art .dp-pill-t {
  color: var(--neutral-150-action);
}

.dp-surface-paper .dp-pill {
  background: color-mix(in srgb, var(--white-100) 70%, transparent);
  box-shadow: 0 0 0 1px var(--charcoal-a10);
}

.dp-surface-paper .dp-pill-n {
  color: var(--dp-charcoal);
}

.dp-surface-paper .dp-pill-t {
  color: var(--neutral-600-secondary);
}

.dp-hint {
  position: absolute;
  bottom: 46px;
  left: 50%;
  width: 48px;
  height: 48px;
  margin-left: -24px;
}

.dp-hint i {
  position: absolute;
  left: 50%;
  width: 13px;
  height: 13px;
  margin-left: -6.5px;
  border-top: 2.5px solid currentColor;
  border-left: 2.5px solid currentColor;
  transform: rotate(45deg);
}

.dp-hint i:first-child {
  top: 13px;
}

.dp-hint i:last-child {
  top: 21px;
}

.dp-surface-art .dp-hint {
  color: color-mix(in srgb, var(--dp-paper) 70%, transparent);
}

.dp-surface-paper .dp-hint {
  color: var(--neutral-400-quiet);
}

/* ---- ending (drawn by the app) */

.dp-ending {
  gap: 32px;
  padding: 0 32px;
}

.dp-ending-title {
  font: 600 33px/40px var(--font-serif);
  letter-spacing: -0.02em;
}

.dp-cal {
  display: flex;
  justify-content: space-between;
}

.dp-cal-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.dp-cal-letter {
  font: 600 13px/18px var(--font-sans);
  color: var(--neutral-500-muted);
}

.dp-cal-ring {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--neutral-200-line);
  border-radius: 50%;
  font: 600 16px/24px var(--font-sans);
  color: var(--neutral-600-secondary);
}

.dp-cal-ring.is-today {
  border-color: var(--orange-500);
  background: var(--orange-050);
  color: var(--orange-500);
}

.dp-count {
  font: 400 16px/24px var(--font-sans);
  color: var(--neutral-600-secondary);
}

.dp-cta {
  position: absolute;
  left: 32px;
  right: 32px;
  bottom: 50px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--orange-500);
  color: var(--dp-paper);
  font: 600 18px/26px var(--font-sans);
}

.dp-cta.is-live {
  cursor: pointer;
}

/* ---- crisis card (no frame; drawn as the app draws it) */

.dp-crisis {
  gap: 24px;
}

.dp-crisis-msg {
  font: 400 19px/28px var(--font-serif);
}

.dp-resources {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dp-resource {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  border-radius: 16px;
  background: var(--tint-05);
}

.dp-res-name {
  font: 600 19px/28px var(--font-sans);
}

.dp-res-contact {
  font: 600 16px/24px var(--font-sans);
  color: var(--orange-500);
}

.dp-res-detail {
  font: 400 13px/18px var(--font-sans);
  letter-spacing: 0.01em;
  color: var(--neutral-600-secondary);
}
