:root {
  color-scheme: dark;
  --bg: #071b22;
  --panel: #0a2630;
  --panel-2: #0e313b;
  --ink: #f5f8f6;
  --muted: #9fb4b7;
  --grid: rgba(220, 236, 235, 0.24);
  --accent: #f3b64b;
  --accent-2: #6ed3bd;
  --danger: #ff7f6e;
  --hour-height: 60px;
  --time-col: 64px;
  --day-min: 132px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(110, 211, 189, 0.16), transparent 34rem),
    linear-gradient(135deg, #06171d 0%, #0a222a 52%, #101e29 100%);
  color: var(--ink);
  font-family: Inter, system-ui, sans-serif;
}

button,
select,
input {
  font: inherit;
}

.app {
  width: min(1460px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo,
.brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
}

.brand-logo {
  display: block;
  border-radius: 8px;
  filter: drop-shadow(0 14px 18px rgba(0, 0, 0, 0.28));
}

.brand-mark {
  border: 1px solid rgba(255, 255, 255, 0.26);
  background:
    linear-gradient(90deg, transparent 48%, rgba(255, 255, 255, 0.22) 49%, rgba(255, 255, 255, 0.22) 51%, transparent 52%),
    linear-gradient(0deg, transparent 48%, rgba(255, 255, 255, 0.22) 49%, rgba(255, 255, 255, 0.22) 51%, transparent 52%),
    linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 8px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
}

.tool-card > span[aria-hidden="true"] {
  position: relative;
  min-width: 34px;
  color: transparent;
}

.tool-card > span[aria-hidden="true"]::after {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0;
}

#addEventButton > span[aria-hidden="true"]::after {
  content: "+";
  font-size: 1rem;
}

#settingsButton > span[aria-hidden="true"]::after {
  content: "SET";
}

#backgroundButton > span[aria-hidden="true"]::after {
  content: "BG";
}

#shareButton > span[aria-hidden="true"]::after {
  content: "UP";
}

#resetButton > span[aria-hidden="true"]::after {
  content: "RST";
}

h1,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.4rem, 2vw, 2rem);
  letter-spacing: 0;
  line-height: 1.05;
}

.brand p {
  color: var(--muted);
  margin-top: 4px;
  font-size: 0.92rem;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

#jsonButton {
  background: rgba(110, 211, 189, 0.16);
  border-color: rgba(110, 211, 189, 0.34);
}

button,
.file-button {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  min-height: 38px;
  padding: 0 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.tool-card input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

button[hidden],
[hidden] {
  display: none !important;
}

button:hover,
.file-button:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.32);
}

#downloadButton {
  background: linear-gradient(135deg, #d99628, #c86b2d);
  border-color: rgba(255, 255, 255, 0.24);
  color: #111923;
  font-weight: 800;
}

.file-button input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.controls {
  display: grid;
  grid-template-columns: repeat(6, minmax(110px, 1fr));
  gap: 8px;
  padding: 10px;
  margin-bottom: 12px;
  background: rgba(6, 23, 29, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
}

.controls label {
  min-width: 0;
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.controls select,
.controls input[type="range"] {
  width: 100%;
}

.controls select {
  color: var(--ink);
  background: #0d2b35;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  min-height: 36px;
  padding: 0 10px;
}

.controls label.toggle {
  display: flex;
  align-items: end;
  gap: 8px;
  padding-top: 20px;
}

.toggle span {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-transform: none;
  color: var(--ink);
  font-size: 0.9rem;
}

.toggle input {
  inline-size: 18px;
  block-size: 18px;
  accent-color: var(--accent);
}

.status {
  min-height: 22px;
  margin-bottom: 8px;
  color: #ffd68b;
  font-size: 0.92rem;
}

.status:empty {
  display: none;
}

.builder-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  gap: 14px;
  align-items: start;
}

.schedule-viewport {
  overflow: auto;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #06222b;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
  max-height: calc(100vh - 185px);
}

.schedule-shell {
  width: max(100%, calc(var(--time-col) + (var(--day-count) * var(--day-min))));
  min-width: calc(var(--time-col) + (var(--day-count) * var(--day-min)));
  background:
    linear-gradient(rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.02)),
    var(--bg);
  padding-bottom: 12px;
}

.schedule-shell.export-mode {
  width: calc(var(--time-col) + (var(--day-count) * var(--day-min)));
  padding-bottom: 0;
}

.schedule-title {
  display: none;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  padding: 10px;
  color: #fff;
  font-family: "Roboto Slab", Georgia, serif;
  font-size: 1.35rem;
  font-weight: 800;
}

.schedule-title.visible {
  display: flex;
}

.week-header {
  position: sticky;
  top: 0;
  z-index: 8;
  display: grid;
  grid-template-columns: var(--time-col) repeat(var(--day-count), minmax(var(--day-min), 1fr));
  background: rgba(6, 31, 39, 0.96);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--grid);
}

.schedule-shell.export-mode .week-header {
  position: static;
  top: auto;
}

.schedule-viewport.export-mode {
  overflow: visible;
}

.corner-cell,
.day-label {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: "Roboto Slab", Georgia, serif;
  font-size: 1.05rem;
  font-weight: 800;
}

.day-label {
  border-left: 1px solid var(--grid);
}

.timetable {
  position: relative;
  display: grid;
  grid-template-columns: var(--time-col) repeat(var(--day-count), minmax(var(--day-min), 1fr));
  min-height: calc((var(--end-hour) - var(--start-hour)) * var(--hour-height));
}

.time-axis {
  position: relative;
  background: rgba(1, 19, 25, 0.4);
  border-right: 1px solid var(--grid);
}

.time-label {
  position: absolute;
  left: 0;
  right: 0;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  color: #fff;
  font-family: "Roboto Slab", Georgia, serif;
  font-size: 1.05rem;
  font-weight: 800;
  text-align: center;
  line-height: 1.12;
}

.day-lane {
  position: relative;
  min-height: calc((var(--end-hour) - var(--start-hour)) * var(--hour-height));
  border-left: 1px solid var(--grid);
  background-image: linear-gradient(to bottom, var(--grid) 1px, transparent 1px);
  background-size: 100% var(--hour-height);
}

.day-lane:last-child {
  border-right: 1px solid var(--grid);
}

.event {
  position: absolute;
  z-index: 3;
  display: flex;
  color: var(--event-fg);
  background:
    linear-gradient(rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0)),
    var(--event-bg);
  border: 1px solid rgba(255, 255, 255, 0.86);
  border-radius: 4px;
  box-shadow: 0 11px 22px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

.event::after {
  display: none;
}

.event-content {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  padding: 7px 7px 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow: hidden;
}

.event.center .event-content {
  text-align: center;
  align-items: center;
}

.event-title {
  width: 100%;
  font-family: "Roboto Slab", Georgia, serif;
  font-size: clamp(0.72rem, 0.85vw, 0.9rem);
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: break-word;
  word-break: normal;
}

.event-details {
  width: 100%;
  font-family: "Roboto Slab", Georgia, serif;
  font-size: clamp(0.66rem, 0.72vw, 0.78rem);
  font-weight: 700;
  line-height: 1.28;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.event-time {
  width: 100%;
  margin-top: auto;
  font-size: 0.66rem;
  font-weight: 700;
  line-height: 1.2;
  opacity: 0.96;
}

.event.compact .event-content {
  gap: 3px;
  padding: 6px;
}

.event.compact .event-details {
  display: none;
}

.event.hide-details .event-details {
  display: none;
}

.empty-state {
  appearance: none;
  border: 0;
  position: absolute;
  left: var(--time-col);
  right: 0;
  top: 68px;
  min-height: 220px;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}

.empty-state:hover,
.empty-state:focus-visible {
  color: var(--accent);
  outline: 0;
}

.side-panel {
  display: grid;
  gap: 10px;
  position: sticky;
  top: 14px;
}

.tool-card {
  min-height: 58px;
  width: 100%;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(8, 31, 39, 0.92);
  color: var(--ink);
  font-weight: 800;
  text-align: left;
}

.tool-card.primary {
  background: #d8d2d4;
  color: #0d2430;
}

.tool-card.danger {
  border-color: rgba(255, 127, 110, 0.26);
}

.tool-card span:last-child {
  font-size: 1.2rem;
  line-height: 1;
}

.tool-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.tool-row button {
  min-height: 46px;
  padding: 0 8px;
  font-size: 0.82rem;
  font-weight: 800;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 11, 15, 0.64);
  backdrop-filter: blur(2px);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(620px, calc(100vw - 28px));
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: #082a34;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.45);
}

.compact-modal {
  width: min(560px, calc(100vw - 28px));
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.13);
}

.modal-header h2 {
  margin: 0;
  font-family: "Roboto Slab", Georgia, serif;
  font-size: 1.35rem;
  line-height: 1.1;
}

.icon-button {
  min-height: 32px;
  width: 32px;
  padding: 0;
  border-radius: 999px;
  font-size: 1.2rem;
}

.modal-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}

.field,
.check-field {
  min-width: 0;
}

.field {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-family: "Roboto Slab", Georgia, serif;
  font-weight: 800;
}

.field span,
.field legend {
  color: var(--ink);
  font-size: 0.92rem;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background: #061e26;
  color: var(--ink);
  padding: 9px 10px;
}

.field textarea {
  resize: vertical;
  line-height: 1.35;
}

.field input[type="color"] {
  padding: 3px;
  cursor: pointer;
}

.copy-section {
  padding: 12px;
  border: 1px solid rgba(110, 211, 189, 0.24);
  border-radius: 8px;
  background: rgba(110, 211, 189, 0.08);
}

.copy-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px;
  gap: 8px;
}

.copy-controls button {
  min-height: 42px;
  font-weight: 800;
  background: rgba(110, 211, 189, 0.16);
  border-color: rgba(110, 211, 189, 0.42);
}

fieldset.field {
  border: 0;
  padding: 0;
  margin: 0;
}

.span-2 {
  grid-column: 1 / -1;
}

.day-picker {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 6px;
  overflow: hidden;
}

.day-picker label {
  min-height: 40px;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: #061e26;
  border-left: 1px solid rgba(255, 255, 255, 0.12);
  cursor: pointer;
  font: 800 0.9rem "Roboto Slab", Georgia, serif;
}

.day-picker label:first-child {
  border-left: 0;
}

.day-picker input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.day-picker label:has(input:checked) {
  background: #d8d2d4;
  color: #0d2430;
}

.color-preview {
  min-height: 44px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  font: 800 1rem "Roboto Slab", Georgia, serif;
}

.check-field {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 800;
}

.check-field input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.modal-footer {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.13);
}

.modal-footer.add-mode {
  grid-template-columns: 1fr;
}

.modal-footer button {
  min-height: 42px;
  font-weight: 800;
}

.submit-button {
  background: rgba(110, 211, 189, 0.18);
  border-color: rgba(110, 211, 189, 0.42);
}

.danger-button {
  background: rgba(255, 127, 110, 0.14);
  border-color: rgba(255, 127, 110, 0.42);
}

.event {
  cursor: pointer;
}

.event:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 820px) {
  .app {
    width: min(100vw - 16px, 1460px);
    padding-top: 10px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .actions {
    width: 100%;
    justify-content: flex-start;
  }

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

  .builder-layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: static;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tool-row {
    grid-column: 1 / -1;
  }

  .schedule-viewport {
    max-height: calc(100vh - 278px);
  }

  .modal-body,
  .modal-footer {
    grid-template-columns: 1fr;
  }

  .copy-controls {
    grid-template-columns: 1fr;
  }

  .day-picker {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media print {
  body {
    background: #fff;
  }

  .topbar,
  .controls,
  .status,
  .side-panel {
    display: none;
  }

  .builder-layout {
    display: block;
  }

  .app {
    width: 100%;
    padding: 0;
  }

  .schedule-viewport {
    max-height: none;
    overflow: visible;
    border: 0;
    box-shadow: none;
  }
}
