:root {
  color-scheme: light;
  --bg: #f3f1ec;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-border: rgba(24, 30, 44, 0.12);
  --ink: #162130;
  --muted: #5c6878;
  --accent: #1f5eff;
  --accent-soft: rgba(31, 94, 255, 0.12);
  --shadow: 0 18px 40px rgba(17, 29, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "SF Pro Text", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(36, 93, 197, 0.12), transparent 32%),
    linear-gradient(180deg, #f8f6f2 0%, var(--bg) 100%);
  color: var(--ink);
}

body {
  overscroll-behavior: none;
  height: 100vh;
}

button,
input,
label {
  font: inherit;
}

button,
.file-button {
  border: 1px solid rgba(21, 33, 47, 0.14);
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.56rem 0.78rem;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
  line-height: 1.15;
}

button:hover,
.file-button:hover {
  background: white;
  border-color: rgba(31, 94, 255, 0.28);
}

button:active,
.file-button:active {
  transform: translateY(1px);
}

button.is-active {
  background: var(--accent);
  color: white;
  border-color: transparent;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1rem;
  background: rgba(248, 246, 242, 0.9);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(27, 35, 48, 0.08);
}

.brand-group {
  display: grid;
  gap: 0.15rem;
}

.brand {
  font-size: 1.12rem;
  font-weight: 700;
}

.status-line {
  color: var(--muted);
  font-size: 0.86rem;
}

.tab-strip,
.file-strip,
.segmented,
.selection-actions,
.sideb-actions,
.view-top-controls,
.follow-controls,
.marker-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.42rem;
}

#nextWindowButton,
#mobileNextButton {
  order: 1;
}

#markerWindowLabel {
  order: 2;
}

#previousWindowButton,
#mobilePrevButton {
  order: 3;
}

.view-menu-wrap {
  position: relative;
}

.view-options-menu {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 30;
  width: min(22rem, calc(100vw - 2rem));
  max-width: calc(100vw - 1.5rem);
  max-height: calc(100vh - 1.5rem);
  overflow: auto;
  padding: 0.7rem;
  display: grid;
  gap: 0.45rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid rgba(18, 28, 42, 0.12);
  box-shadow: 0 18px 42px rgba(17, 29, 42, 0.18);
  backdrop-filter: blur(12px);
}

.view-options-menu.is-hidden {
  display: none;
}

.view-options-title {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.view-options-menu > label:not(.slider-row) {
  display: flex;
  align-items: center;
  gap: 0.34rem;
  font-size: 0.8rem;
  min-height: 1.7rem;
}

.focus-width-control {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.55rem;
  border: 1px solid rgba(21, 33, 47, 0.14);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
}

.focus-width-control.is-hidden,
.is-hidden {
  display: none !important;
}

.focus-width-control input {
  inline-size: clamp(11rem, 18vw, 15rem);
  block-size: 1.75rem;
  cursor: ew-resize;
  accent-color: var(--accent);
}

.focus-width-control input[type="range"]::-webkit-slider-runnable-track {
  height: 0.38rem;
  border-radius: 999px;
  background: rgba(31, 94, 255, 0.18);
}

.focus-width-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  margin-top: -0.33rem;
  width: 1rem;
  height: 1rem;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  box-shadow: 0 3px 10px rgba(31, 94, 255, 0.28);
}

.focus-width-control input[type="range"]::-moz-range-track {
  height: 0.38rem;
  border: none;
  border-radius: 999px;
  background: rgba(31, 94, 255, 0.18);
}

.focus-width-control input[type="range"]::-moz-range-thumb {
  width: 1rem;
  height: 1rem;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 3px 10px rgba(31, 94, 255, 0.28);
}

.print-notes {
  display: none;
}

.file-button input {
  display: none;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0.45rem;
  padding: 0.8rem;
  min-height: 0;
  overflow: hidden;
}

.controls-panel,
.canvas-panel {
  min-height: 0;
}

.controls-panel {
  order: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: start;
  align-content: start;
  overflow: visible;
  padding-bottom: 0;
}

.panel-block,
.canvas-panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.panel-block {
  padding: 0.36rem 0.48rem;
  display: grid;
  gap: 0.22rem;
  align-content: start;
  min-width: 0;
  border-radius: 14px;
}

.controls-panel .panel-block {
  box-shadow: 0 10px 26px rgba(17, 29, 42, 0.08);
  min-width: 0;
  flex: 0 1 auto;
}

.controls-panel > .panel-block {
  min-width: 0;
}

.panel-body {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
}

.block-title {
  font-size: 0.64rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.block-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.35rem;
  width: auto;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  cursor: default;
}

.block-header:hover,
.block-header:active {
  background: transparent;
  border-color: transparent;
  transform: none;
}

.block-summary {
  min-width: 0;
  color: var(--muted);
  font-size: 0.64rem;
  line-height: 1.25;
  text-align: left;
}

.panel-block[data-collapsible] .block-header::after {
  content: "";
  width: 0.48rem;
  height: 0.48rem;
  margin-left: 0.1rem;
  border-right: 1.5px solid rgba(22, 33, 48, 0.45);
  border-bottom: 1.5px solid rgba(22, 33, 48, 0.45);
  transform: rotate(45deg);
  transition: transform 120ms ease;
}

.panel-block.is-collapsed .block-header::after {
  transform: rotate(-45deg) translateY(-1px);
}

.panel-block.is-collapsed .panel-body {
  display: none;
}

.palette-grid {
  display: flex;
  gap: 0.22rem;
  flex-wrap: wrap;
  align-items: center;
}

.color-pair {
  display: flex;
  align-items: center;
  margin: 0;
}

.color-pair button {
  position: relative;
  width: 2rem;
  height: 2rem;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}

.color-pair-front,
.color-pair-back {
  position: absolute;
  width: 1.18rem;
  height: 1.18rem;
  border-radius: 999px;
  border: 1.5px solid rgba(18, 24, 36, 0.18);
  box-shadow: 0 4px 10px rgba(17, 29, 42, 0.12);
}

.color-pair-back {
  top: 0.18rem;
  right: 0.05rem;
}

.color-pair-front {
  bottom: 0.05rem;
  left: 0.05rem;
  z-index: 1;
}

.palette-toolbar {
  display: flex;
  align-items: center;
  gap: 0.28rem;
  flex-wrap: wrap;
}

.palette-expand {
  padding: 0.26rem 0.48rem;
  min-height: 1.9rem;
  font-size: 0.72rem;
}

.palette-editor {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(4rem, max-content));
  gap: 0.3rem;
  width: 100%;
}

.palette-editor.is-hidden {
  display: none;
}

.swatch-row {
  display: flex;
  gap: 0.16rem;
  align-items: center;
  justify-items: start;
}

.swatch-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  padding: 0;
  border-radius: 999px;
}

.swatch-preview {
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 999px;
  border: 1.5px solid rgba(18, 24, 36, 0.12);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.72rem;
  position: relative;
}

.swatch-preview.is-primary {
  box-shadow: 0 0 0 2px rgba(31, 94, 255, 0.28);
  border-color: rgba(31, 94, 255, 0.8);
}

.swatch-preview.is-secondary::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 999px;
  border: 1px dashed rgba(17, 24, 32, 0.18);
}

.swatch-preview.spacer {
  background:
    repeating-linear-gradient(135deg, rgba(98, 106, 116, 0.18) 0, rgba(98, 106, 116, 0.18) 6px, transparent 6px, transparent 12px),
    rgba(255, 255, 255, 0.92);
  color: #56606f;
}

.swatch-chip input[type="color"] {
  inline-size: 1.7rem;
  block-size: 1.1rem;
  border: none;
  background: transparent;
  padding: 0;
}

.palette-editor-chip {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 0.22rem;
  min-width: 0;
}

.palette-editor-chip .swatch-preview {
  width: 1.3rem;
  height: 1.3rem;
  font-size: 0.62rem;
}

.token-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
}

.token-grid button {
  min-width: 1.9rem;
  padding: 0.28rem 0.4rem;
  font-size: 0.74rem;
}

.mini-note {
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.3;
}

.panel-colors .mini-note {
  display: none;
}

.slider-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.36rem;
  align-items: center;
}

.segmented,
.selection-actions,
.sideb-actions {
  gap: 0.28rem;
}

.segmented button,
.selection-actions button,
.sideb-actions button {
  padding: 0.3rem 0.46rem;
  font-size: 0.74rem;
}

#renderOptionsPanel {
  align-items: start;
}

#renderOptionsPanel .panel-body {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  align-items: start;
}

#renderOptionsPanel .block-header {
  grid-column: 1 / -1;
}

#renderOptionsPanel .slider-row {
  grid-column: span 2;
}

#renderOptionsPanel .panel-body > label:not(.slider-row) {
  display: flex;
  align-items: center;
  gap: 0.34rem;
  font-size: 0.76rem;
  min-height: 1.7rem;
}

.canvas-panel {
  order: 2;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.canvas-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0.75rem 0;
}

.render-options-summary {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.mobile-actions {
  display: none;
  gap: 0.45rem;
  padding: 0 0.75rem 0.65rem;
  flex-wrap: nowrap;
}

.canvas-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0.35rem 0.75rem 0.75rem;
  border-radius: 14px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: inset 0 0 0 1px rgba(18, 28, 42, 0.08);
}

.canvas-scroll {
  position: absolute;
  inset: 0;
  overflow: auto;
  touch-action: pan-x pan-y;
  background: transparent;
}

.canvas-overlay {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  background: rgba(248, 246, 242, 0.94);
  backdrop-filter: blur(10px);
}

.canvas-overlay canvas {
  display: block;
}

.canvas-overlay-top,
.canvas-overlay-bottom {
  left: 42px;
  right: 0;
  height: 30px;
}

.canvas-overlay-top {
  top: 0;
  border-bottom: 1px solid rgba(18, 28, 42, 0.08);
}

.canvas-overlay-left,
.canvas-overlay-right {
  top: 30px;
  bottom: 0;
  width: 42px;
}

.canvas-overlay-left {
  left: 0;
  border-right: 1px solid rgba(18, 28, 42, 0.08);
}

.canvas-overlay-bottom,
.canvas-overlay-right {
  display: none;
}

.canvas-corner {
  position: absolute;
  z-index: 4;
  background: rgba(248, 246, 242, 0.96);
  backdrop-filter: blur(10px);
}

.canvas-corner-top-left {
  top: 0;
  left: 0;
  width: 42px;
  height: 30px;
  border-right: 1px solid rgba(18, 28, 42, 0.08);
  border-bottom: 1px solid rgba(18, 28, 42, 0.08);
}

#chartCanvas {
  display: block;
  background: rgba(255, 255, 255, 0.98);
}

.context-menu {
  position: fixed;
  z-index: 40;
  display: grid;
  gap: 0.25rem;
  min-width: 170px;
  padding: 0.45rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(18, 28, 42, 0.12);
  box-shadow: 0 18px 42px rgba(17, 29, 42, 0.18);
  backdrop-filter: blur(12px);
}

.context-menu.is-hidden {
  display: none;
}

.context-menu button {
  justify-content: flex-start;
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
}

body.is-view-mode .controls-panel {
  display: none;
}

body.is-view-mode .workspace {
  grid-template-rows: minmax(0, 1fr);
}

body.is-view-mode .mobile-actions {
  display: flex;
}

body.is-view-mode .mobile-actions button {
  flex: 1 1 0;
  min-height: 3.2rem;
  font-size: 1rem;
}

@media (max-width: 980px) {
  .controls-panel {
    gap: 0.45rem;
  }
}

@media (max-width: 720px) {
  .topbar {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
    padding: 0.7rem 0.75rem;
  }

  .workspace {
    grid-template-rows: auto minmax(260px, 48vh);
    align-content: start;
    padding: 0.65rem;
    overflow: auto;
  }

  .panel-block,
  .canvas-panel {
    border-radius: 16px;
  }

  .mobile-actions {
    display: flex;
  }

  .brand-group {
    gap: 0.08rem;
  }

  .panel-colors .mini-note {
    display: block;
  }

  .brand {
    font-size: 1rem;
  }

  .status-line {
    font-size: 0.8rem;
  }

  .tab-strip,
  .file-strip {
    width: 100%;
  }

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

  .file-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .tab-strip button,
  .file-strip button,
  .file-button {
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  .canvas-panel {
    min-height: 260px;
  }

  .canvas-stage {
    min-height: 190px;
  }

  .controls-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 0.38rem;
    overflow: visible;
  }

  .controls-panel > .panel-block {
    min-width: 0;
    width: auto;
    flex: 1 1 auto;
  }

  .panel-tools,
  .panel-colors {
    width: 100%;
  }

  .panel-block[data-collapsible] .block-header {
    cursor: pointer;
  }

  .segmented,
  .sideb-actions {
    display: flex;
    flex-wrap: wrap;
  }

  .selection-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .token-grid {
    display: flex;
    flex-wrap: wrap;
  }

  .palette-grid {
    display: flex;
    align-items: start;
  }

  .view-options-menu {
    position: fixed;
    top: auto;
    right: 0.75rem;
    left: 0.75rem;
    width: auto;
    max-height: min(65vh, 34rem);
    overflow: auto;
  }

  .canvas-toolbar {
    padding: 0.55rem 0.6rem 0;
  }

  .render-options-summary {
    font-size: 0.74rem;
  }

  .focus-width-control {
    width: 100%;
    justify-content: space-between;
  }

  .focus-width-control input {
    inline-size: 100%;
  }

  .block-summary {
    max-width: 52vw;
    font-size: 0.68rem;
  }

  .selection-actions button,
  .token-grid button,
  .segmented button,
  .sideb-actions button,
  .follow-controls button,
  .marker-controls button,
  .mobile-actions button,
  .file-strip button,
  .file-button,
  .tab-strip button {
    min-height: 38px;
    font-size: 0.76rem;
    padding: 0.34rem 0.46rem;
  }

  .swatch-preview {
    width: 1.45rem;
    height: 1.45rem;
  }
}

@media (max-width: 480px) {
  .workspace {
    grid-template-rows: minmax(240px, 44vh) auto;
  }

  .canvas-panel {
    min-height: 240px;
  }

  .canvas-stage {
    min-height: 174px;
  }

  .file-strip {
    gap: 0.35rem;
  }

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

  .view-options-menu {
    left: 0.65rem;
    right: 0.65rem;
  }
}

@media print {
  body {
    height: auto;
    background: white;
  }

  .topbar,
  .controls-panel,
  .canvas-toolbar,
  .mobile-actions {
    display: none !important;
  }

  .workspace,
  .app-shell {
    display: block;
    height: auto;
    padding: 0;
  }

  .canvas-panel {
    box-shadow: none;
    border: none;
    background: white;
  }

  .canvas-stage {
    position: static;
    overflow: visible;
    min-height: 0;
    margin: 0;
    box-shadow: none;
    border: none;
    break-inside: avoid;
  }

  .canvas-scroll {
    position: static;
    inset: auto;
    overflow: visible;
  }

  .canvas-overlay,
  .canvas-corner {
    display: none !important;
  }

  #chartCanvas {
    display: block;
    max-width: 100%;
    height: auto !important;
  }

  .print-notes {
    display: block;
    margin-top: 0.4in;
    font-size: 11pt;
    color: #111;
  }
}
