:root {
  color-scheme: light;
  --ink: #07142b;
  --muted: #536176;
  --line: #142033;
  --soft-line: #ced7e5;
  --panel: #f7f9fc;
  --pic: #b8171c;
  --pic-soft: #fde5e5;
  --fo: #174fca;
  --fo-soft: #e5eefc;
  --cpm: #28761d;
  --cpm-soft: #ebf3df;
  --focus: #1674e8;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
}

body {
  min-width: 320px;
  color: var(--ink);
  background: #f5f7fa;
  -webkit-tap-highlight-color: transparent;
}

button,
label,
legend,
.return-card,
.marker,
.active-rest {
  -webkit-user-select: none;
  user-select: none;
}

input,
select {
  font: inherit;
  color: inherit;
}

input:focus-visible,
select:focus-visible,
.segmented-control input:focus-visible + label {
  outline: 3px solid color-mix(in srgb, var(--focus) 65%, transparent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.portrait-message {
  display: none;
}

.app-shell {
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  overflow: hidden;
}

.app-header {
  height: clamp(48px, 7vh, 64px);
  display: grid;
  grid-template-columns: minmax(90px, 1fr) auto minmax(90px, 1fr);
  align-items: center;
  padding: 0 clamp(14px, 2vw, 28px);
  border-bottom: 1px solid var(--soft-line);
  background: rgba(249, 251, 253, 0.88);
  box-shadow: 0 5px 24px rgba(7, 20, 43, 0.045);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  backdrop-filter: saturate(160%) blur(16px);
}

.app-header h1 {
  margin: 0;
  color: var(--ink);
  background: linear-gradient(115deg, #07142b 20%, #174f86 100%);
  -webkit-background-clip: text;
  background-clip: text;
  font-size: clamp(1.35rem, 2.75vw, 2.3rem);
  font-weight: 720;
  line-height: 1;
  letter-spacing: -0.035em;
  text-align: center;
  -webkit-text-fill-color: transparent;
}

.brand-mark {
  width: clamp(64px, 7.5vw, 104px);
  display: flex;
  align-items: center;
  justify-self: end;
  color: var(--ink);
}

.brand-mark svg {
  width: clamp(28px, 3vw, 40px);
  height: auto;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-wing {
  height: 14px;
  flex: 1;
  background: currentColor;
  clip-path: polygon(0 0, 100% 25%, 100% 75%, 18% 100%, 0 76%, 70% 58%, 0 38%);
}

.brand-wing-right {
  transform: scaleX(-1);
}

.header-actions {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-self: start;
  gap: 8px;
}

.header-button {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid #cbd5e3;
  border-radius: 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 2px 8px rgba(7, 20, 43, 0.08);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-touch-callout: none;
}

.header-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.header-button svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.panel-toggle-arrow {
  transform-origin: center;
}

.header-button:hover {
  background: #fff;
}

.header-button:active:not(:disabled) {
  background: #eef3f9;
  transform: scale(0.96);
}

.header-button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 65%, transparent);
  outline-offset: 2px;
}

.panel-toggle[aria-expanded="false"] {
  border-color: var(--ink);
  color: #fff;
  background: var(--ink);
}

.panel-toggle[aria-expanded="false"] .panel-toggle-arrow {
  transform: scaleX(-1);
}

.workspace {
  width: 100%;
  height: calc(100dvh - clamp(48px, 7vh, 64px) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: clamp(180px, 20vw, 248px) minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.workspace.controls-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}

.workspace.controls-collapsed .control-panel {
  padding-right: 0;
  padding-left: 0;
  border-right: 0;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(-100%);
}

.control-panel {
  min-width: 0;
  min-height: 0;
  padding: clamp(12px, 1.7vh, 22px) clamp(12px, 1.35vw, 20px);
  overflow-x: hidden;
  overflow-y: auto;
  border-right: 1px solid #d9e0ea;
  background: #f7f9fc;
  scrollbar-width: thin;
}

.field-group {
  min-width: 0;
  margin: 0 0 clamp(10px, 1.45vh, 18px);
}

.field-group > label,
.field-group > legend {
  display: block;
  margin: 0 0 7px;
  padding: 0;
  color: var(--ink);
  font-size: clamp(0.72rem, 1vw, 0.96rem);
  font-weight: 720;
  letter-spacing: 0.055em;
  line-height: 1.15;
  text-transform: uppercase;
}

.field-group input[type="text"],
.field-group select {
  display: block;
  inline-size: 100%;
  min-width: 0;
  min-inline-size: 0;
  max-width: 100%;
  max-inline-size: 100%;
  width: 100%;
  height: 44px;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid #d3dbe7;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 1px 2px rgba(7, 20, 43, 0.04), inset 0 1px rgba(255, 255, 255, 0.8);
  font-size: clamp(1rem, 1.55vw, 1.28rem);
  font-weight: 680;
  line-height: 44px;
  letter-spacing: 0.015em;
  text-align: center;
}

.clock-input[readonly] {
  cursor: pointer;
  caret-color: transparent;
  touch-action: manipulation;
}

.time-picker-open {
  overflow: hidden;
}

.time-picker-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: calc(16px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  background: rgba(7, 20, 43, 0.28);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.time-picker-dialog {
  width: min(430px, 92vw);
  max-height: min(390px, 88dvh);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 24px;
  background: rgba(249, 251, 253, 0.97);
  box-shadow: 0 24px 80px rgba(7, 20, 43, 0.3);
}

.time-picker-header {
  padding: 14px 20px 8px;
  text-align: center;
}

.time-picker-header div {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 14px;
}

.time-picker-header span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.time-picker-header strong {
  color: var(--ink);
  font-size: 1.55rem;
  font-variant-numeric: tabular-nums;
}

.time-picker-columns {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 20px minmax(0, 1fr);
  gap: 5px;
  padding: 0 18px;
}

.time-picker-column {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 5px;
}

.time-picker-column > span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-align: center;
  text-transform: uppercase;
}

.time-picker-colon {
  align-self: center;
  color: var(--muted);
  font-size: 1.7rem;
  font-weight: 800;
  text-align: center;
}

.time-picker-list {
  min-height: 150px;
  overflow-y: auto;
  border: 1px solid #d5deea;
  border-radius: 14px;
  background: #fff;
  scrollbar-width: none;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.time-picker-list::-webkit-scrollbar {
  display: none;
}

.time-picker-list button {
  width: 100%;
  min-height: 46px;
  display: block;
  padding: 0;
  border: 0;
  border-bottom: 1px solid #edf1f6;
  color: var(--ink);
  background: transparent;
  font-size: 1.25rem;
  font-weight: 680;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  touch-action: manipulation;
}

.time-picker-list button:last-child {
  border-bottom: 0;
}

.time-picker-list button.is-selected {
  color: #fff;
  background: var(--ink);
}

.time-picker-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px 18px 16px;
}

.time-picker-actions button {
  min-height: 44px;
  border: 1px solid #cbd5e3;
  border-radius: 12px;
  color: var(--ink);
  background: #fff;
  font-size: 1rem;
  font-weight: 750;
  cursor: pointer;
  touch-action: manipulation;
}

.time-picker-actions .time-picker-done {
  border-color: var(--ink);
  color: #fff;
  background: var(--ink);
}

.field-group select {
  min-height: 44px;
  font-size: clamp(0.86rem, 1.2vw, 1.05rem);
  font-weight: 680;
  line-height: normal;
  text-align: center;
  text-align-last: center;
}

.reference-fieldset {
  min-width: 0;
  padding: 0;
  border: 0;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1.12fr;
  min-height: 44px;
  overflow: hidden;
  border: 1px solid #c5d0e1;
  border-radius: 10px;
  background: #edf1f6;
}

.segmented-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.segmented-control label {
  min-width: 0;
  display: grid;
  place-items: center;
  padding: 0 8px;
  border-radius: 9px;
  font-size: clamp(0.8rem, 1.15vw, 1rem);
  font-weight: 750;
  text-transform: uppercase;
  cursor: pointer;
}

.segmented-control input:checked + label {
  color: #fff;
  background: var(--ink);
  box-shadow: 0 3px 8px rgba(7, 20, 43, 0.2);
}

.return-card {
  min-height: 50px;
  display: grid;
  place-content: center;
  gap: 3px;
  margin: -2px 0 clamp(12px, 1.8vh, 22px);
  padding: 8px;
  border: 1px solid #cbd5e3;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.78);
  font-size: clamp(0.82rem, 1.15vw, 1rem);
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
}

.return-card small {
  font-size: 0.82em;
  font-weight: 650;
}

.validation-error {
  min-height: 1.2em;
  margin: -3px 0 0;
  color: #a30c14;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.25;
}

.validation-error:empty {
  display: none;
}

.schedule-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: clamp(34px, 6vh, 54px) minmax(0, 1fr) clamp(27px, 4.5vh, 38px);
  padding: 0 clamp(13px, 1.7vw, 26px) 0 clamp(15px, 1.7vw, 26px);
  background: #fff;
}

.time-markers,
.midpoint-markers {
  position: relative;
  min-width: 0;
}

.marker {
  position: absolute;
  left: var(--position);
  bottom: 7px;
  z-index: 2;
  font-size: clamp(0.9rem, 1.45vw, 1.28rem);
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  transform: translateX(-50%);
}

.time-markers .marker:first-child {
  transform: none;
}

.time-markers .marker:last-child {
  transform: translateX(-100%);
}

.midpoint-markers .marker.midpoint {
  top: 6px;
  bottom: auto;
  display: flex;
  align-items: baseline;
  gap: 4px;
  justify-content: center;
  font-size: clamp(0.84rem, 1.25vw, 1.1rem);
  font-weight: 780;
  text-align: center;
}

.split-duration {
  color: currentColor;
  font-size: 1em;
  font-weight: 750;
  letter-spacing: 0.01em;
  line-height: 1;
  opacity: 0.76;
  white-space: nowrap;
}

.midpoint-time {
  font-weight: 850;
}

.crew-pic {
  color: var(--pic);
}

.crew-fo {
  color: var(--fo);
}

.crew-cpm {
  color: var(--cpm);
}

.chart {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  overflow: hidden;
  border: 1.5px solid var(--line);
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 3px 12px rgba(7, 20, 43, 0.08);
}

.chart-cell {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-content: center;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.chart-cell:nth-child(3n) {
  border-right: 0;
}

.chart-cell:nth-child(n + 7) {
  border-bottom: 0;
}

.active-rest {
  position: relative;
  gap: clamp(3px, 0.9vh, 9px);
  --rest-shield: #fff;
}

.active-rest::before {
  position: absolute;
  inset: 0;
  z-index: 0;
  content: "";
  background: radial-gradient(circle at center, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.26));
}

.pic-rest {
  --rest-shield: var(--pic-soft);
  color: var(--pic);
  background: var(--pic-soft);
}

.fo-rest {
  --rest-shield: var(--fo-soft);
  color: var(--fo);
  background: var(--fo-soft);
}

.cpm-rest {
  --rest-shield: var(--cpm-soft);
  color: var(--cpm);
  background: var(--cpm-soft);
}

.crew-picker {
  position: relative;
  z-index: 4;
  display: inline-grid;
  place-self: center;
  width: min(88%, 330px);
  min-width: 120px;
  border-radius: 0.18em;
  background: var(--rest-shield);
  box-shadow: 0 0 14px 8px var(--rest-shield);
}

.crew-display {
  box-sizing: border-box;
  display: block;
  width: 100%;
  padding: 0.05em 8px 0.08em;
  font-size: clamp(2.2rem, 5.8vw, 5.5rem);
  font-weight: 850;
  letter-spacing: -0.045em;
  line-height: 0.78;
  text-align: center;
  white-space: nowrap;
}

.crew-picker.is-unassigned .crew-display {
  font-size: clamp(1.2rem, 3vw, 2.5rem);
  font-weight: 760;
  letter-spacing: 0.01em;
}

.crew-select {
  position: absolute;
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: transparent;
  opacity: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-appearance: none;
  appearance: none;
}

.crew-select:focus,
.crew-select:focus-visible {
  outline: 0;
  box-shadow: none;
}

.pic-rest .crew-picker {
  color: rgba(184, 23, 28, 0.42);
}

.fo-rest .crew-picker {
  color: rgba(23, 79, 202, 0.42);
}

.cpm-rest .crew-picker {
  color: rgba(40, 118, 29, 0.42);
}

.active-rest .duration {
  position: relative;
  z-index: 4;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--rest-shield);
  box-shadow: 0 0 8px 5px var(--rest-shield);
  color: var(--ink);
  font-size: clamp(0.7rem, 1.23vw, 1.04rem);
  font-weight: 750;
  line-height: 1;
}

.split-line {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 2;
  width: 2px;
  border: 0;
  background: repeating-linear-gradient(to bottom, currentColor 0 7px, transparent 7px 13px);
  opacity: 0.36;
  transform: translateX(-1px);
  pointer-events: none;
}

.split-pic {
  left: 16.6667%;
  color: var(--pic);
}

.split-fo {
  left: 50%;
  color: var(--fo);
}

.split-cpm {
  left: 83.3333%;
  color: var(--cpm);
}

.schedule-panel.is-invalid .time-markers,
.schedule-panel.is-invalid .midpoint-markers,
.schedule-panel.is-invalid .active-rest .duration,
.schedule-panel.is-invalid .split-line,
.schedule-panel.is-waiting .time-markers,
.schedule-panel.is-waiting .midpoint-markers,
.schedule-panel.is-waiting .active-rest .duration,
.schedule-panel.is-waiting .split-line {
  visibility: hidden;
}

@media (max-height: 520px) and (orientation: landscape) {
  .app-header {
    height: 44px;
  }

  .app-header h1 {
    font-size: clamp(1.15rem, 2.65vw, 1.5rem);
    letter-spacing: -0.03em;
  }

  .brand-mark {
    width: clamp(54px, 6.5vw, 72px);
  }

  .header-button {
    width: 44px;
    height: 44px;
    border-radius: 10px;
  }

  .header-button svg {
    width: 21px;
    height: 21px;
  }

  .brand-mark svg {
    width: 27px;
  }

  .brand-wing {
    height: 11px;
  }

  .workspace {
    height: calc(100dvh - 44px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    grid-template-columns: clamp(180px, 20.5vw, 198px) minmax(0, 1fr);
  }

  .control-panel {
    display: grid;
    grid-template-areas:
      "start"
      "selector"
      "reference-time"
      "finish"
      "return"
      "error";
    grid-template-columns: minmax(0, 1fr);
    grid-auto-rows: max-content;
    gap: 3px 8px;
    align-content: start;
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .field-group {
    margin-bottom: 0;
  }

  .start-field {
    grid-area: start;
  }

  .reference-time-field {
    grid-area: reference-time;
  }

  .reference-fieldset {
    grid-area: selector;
  }

  .finish-field {
    grid-area: finish;
  }

  .return-card {
    grid-area: return;
  }

  .validation-error {
    grid-area: error;
  }

  .field-group > label,
  .field-group > legend {
    margin-bottom: 3px;
    font-size: 0.61rem;
  }

  .field-group input[type="text"],
  .field-group select,
  .segmented-control {
    height: 44px;
    min-height: 44px;
  }

  .field-group input[type="text"] {
    padding-right: 8px;
    padding-left: 8px;
    font-size: 1rem;
    font-weight: 680;
    line-height: 44px;
  }

  .field-group select {
    padding-right: 3px;
    padding-left: 6px;
    font-size: 0.82rem;
  }

  .return-card {
    min-height: 44px;
    margin: 0;
    padding: 5px;
  }

  .schedule-panel {
    grid-template-rows: 32px minmax(0, 1fr) 27px;
    padding-bottom: 0;
  }

  .marker {
    bottom: 5px;
  }

  .midpoint-markers .marker.midpoint {
    top: 6px;
  }
}

@media (max-width: 767px) and (orientation: portrait) {
  body {
    background: var(--ink);
  }

  .app-shell {
    display: none;
  }

  .portrait-message {
    min-height: 100dvh;
    display: grid;
    place-content: center;
    gap: 18px;
    padding: calc(24px + env(safe-area-inset-top)) calc(24px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) calc(24px + env(safe-area-inset-left));
    color: #fff;
    text-align: center;
  }

  .portrait-message p {
    max-width: 310px;
    margin: 0;
    font-size: 1.15rem;
    font-weight: 650;
    line-height: 1.45;
  }

  .rotate-icon {
    width: 64px;
    margin: auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
}

@media (prefers-reduced-motion: no-preference) {
  input,
  select,
  .segmented-control label,
  .header-button {
    transition: outline-color 120ms ease, background-color 120ms ease, transform 80ms ease;
  }

  .panel-toggle-arrow {
    transition: transform 180ms ease;
  }

  .workspace {
    transition: grid-template-columns 180ms ease;
  }

  .control-panel {
    transition: opacity 140ms ease, transform 180ms ease;
  }
}
