/* FlashBoard: a remake of the 2006 Flash surfboard designer.
   Gray foam-block panels, hanging trapezoid tabs and indigo curves are kept
   from the original; everything else is quiet. */

:root {
  --stage: #b4b4ba;        /* gutters between panels */
  --bevel: #efeff2;        /* light panel edge */
  --foam: #c9c9cd;         /* 2D drawing boards */
  --grid: #b6b6bd;
  --station: #8a8a94;
  --ink: #4433cc;          /* curves, from the original */
  --ink-soft: #9999cc;     /* control polygons, from the original */
  --fill: rgba(153, 153, 170, 0.42);
  --handle: #8484e4;
  --handle-edge: #2f2a8f;
  --chrome-hi: #8a8b91;    /* parameter panel and tabs */
  --chrome: #6f7076;
  --chrome-lo: #5b5c62;
  --on-chrome: #f5f5f8;
  --night: #26262b;        /* top bar */
  --text: #2a2a33;
  --muted: #5d5d68;
  --danger: #b3261e;

  --font: 'Saira', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --tab-h: 26px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--stage);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------ top bar */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  height: 46px;
  padding: 0 10px 0 16px;
  background: var(--night);
  color: #e6e6ee;
  flex: none;
}

.topbar :focus-visible {
  outline-color: #b9b8ff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0.04em;
  color: #fff;
}

.brand-mark {
  width: 40px;
  height: 16px;
}

.brand-mark path {
  fill: #9d9cf5;
}

.brand-mark .stringer {
  fill: none;
  stroke: var(--ink);
  stroke-width: 0.9;
}

.design-name {
  flex: 1 1 auto;
  min-width: 80px;
  max-width: 360px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: #cfcfda;
  font-size: 15px;
  letter-spacing: 0.02em;
}

.design-name:hover {
  border-color: #45454d;
}

.design-name:focus {
  outline: none;
  border-color: #8886f0;
  background: #1c1c20;
  color: #fff;
}

.actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
}

.tb {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  min-width: 34px;
  justify-content: center;
  padding: 0 9px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: #d4d4de;
  font-size: 14px;
  letter-spacing: 0.03em;
}

.tb:hover:not(:disabled) {
  background: #3a3a42;
  color: #fff;
}

.tb:disabled {
  color: #5e5e68;
}

.tb .caret {
  font-size: 11px;
  opacity: 0.7;
}

.sep {
  width: 1px;
  height: 20px;
  margin: 0 6px;
  background: #44444c;
}

.menu-wrap {
  position: relative;
}

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  width: 260px;
  padding: 6px;
  background: #f3f3f6;
  color: var(--text);
  border: 1px solid #c3c3cb;
  border-radius: 4px;
  box-shadow: 0 10px 28px rgba(20, 20, 40, 0.28);
}

.menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  text-align: left;
}

.menu button i {
  width: 16px;
  color: var(--ink);
}

.menu button:hover,
.menu button:focus-visible {
  background: #e1e0f6;
  outline: none;
}

.menu-note {
  margin: 6px 10px 4px;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--muted);
}

/* ---------------------------------------------------------------- workspace */

.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 44fr) minmax(0, 21fr) minmax(0, 35fr);
  grid-template-rows: minmax(0, 1fr) 236px;
  grid-template-areas:
    'viewer top sections'
    'params side side';
  gap: 5px;
  padding: 5px;
}

.panel {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--bevel);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.panel-3d {
  grid-area: viewer;
}
.panel-params {
  grid-area: params;
}
.panel-top {
  grid-area: top;
}
.panel-sections {
  grid-area: sections;
}
.panel-side {
  grid-area: side;
}

/* Tabs hang from the top edge with one slanted side, as in the original. */
.tab {
  position: absolute;
  top: 0;
  z-index: 2;
  height: var(--tab-h);
  line-height: var(--tab-h);
  background: linear-gradient(#a2a3a9, var(--chrome-hi));
  color: var(--on-chrome);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.07em;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}

.tab-right {
  right: 0;
  padding: 0 16px 0 38px;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 22px 100%);
}

.tab-left {
  left: 0;
  padding: 0 38px 0 16px;
  clip-path: polygon(0 0, 100% 0, calc(100% - 22px) 100%, 0 100%);
}

/* ------------------------------------------------------------------ 3D view */

.panel-3d {
  background:
    radial-gradient(circle at 10% -30%, #d3d3d8 0 46%, transparent 46.25%),
    linear-gradient(165deg, #c9c9ce 0%, #b9b9bf 58%, #cfcfd4 100%);
}

.viewer {
  position: absolute;
  inset: 0;
}

.viewer canvas {
  display: block;
  touch-action: none;
}

.toolbar {
  position: absolute;
  bottom: 8px;
  z-index: 2;
  display: flex;
  gap: 3px;
}

.toolbar-left {
  left: 8px;
}

.toolbar-right {
  right: 8px;
}

.tool {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.55);
  background: linear-gradient(#7b7c82, var(--chrome-lo));
  color: #fff;
  font-size: 17px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.tool:hover {
  background: linear-gradient(#8b8c93, #66676d);
}

.tool[aria-pressed='true'] {
  background: linear-gradient(#9c9cf0, #6765d2);
  border-color: #e7e6ff;
  box-shadow: inset 0 1px 3px rgba(20, 16, 90, 0.45);
}

.tool-sep {
  width: 6px;
}

/* --------------------------------------------------------------- parameters */

.panel-params {
  background:
    radial-gradient(ellipse 90% 140% at 100% 110%, rgba(255, 255, 255, 0.13) 0 50%, transparent 50.5%),
    linear-gradient(172deg, #85868c 0%, var(--chrome) 60%, #64656b 100%);
  color: var(--on-chrome);
}

.groups {
  position: absolute;
  inset: calc(var(--tab-h) + 10px) 12px 26px;
  display: flex;
  gap: 12px;
}

.group {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  padding: calc(var(--tab-h) + 8px) 12px 10px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(0, 0, 0, 0.1);
  box-shadow: inset 0 1px 6px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.group-title {
  position: absolute;
  top: 0;
  left: 0;
  margin: 0;
  height: 24px;
  line-height: 24px;
  padding: 0 30px 0 10px;
  background: linear-gradient(#9d9ea4, #85868c);
  clip-path: polygon(0 0, 100% 0, calc(100% - 18px) 100%, 0 100%);
  font-size: 14.5px;
  font-weight: 500;
  letter-spacing: 0.06em;
}

.field {
  display: grid;
  grid-template-columns: 1fr 68px 18px;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  font-size: 14.5px;
  letter-spacing: 0.03em;
}

.field span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.field em {
  font-style: normal;
  font-size: 12.5px;
  opacity: 0.8;
}

.field input {
  width: 100%;
  height: 26px;
  padding: 0 6px;
  border: 1px solid #505157;
  border-radius: 2px;
  background: #f4f4f7;
  color: var(--text);
  text-align: right;
  font-variant-numeric: tabular-nums;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.18);
}

.field input:focus {
  outline: 2px solid #c3c2ff;
  outline-offset: 0;
}

.field output {
  text-align: right;
  padding-right: 7px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.segmented {
  display: flex;
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.segmented label {
  flex: 1;
  position: relative;
}

.segmented input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}

.segmented span {
  display: block;
  text-align: center;
  height: 28px;
  line-height: 28px;
  font-size: 13.5px;
  letter-spacing: 0.04em;
  background: rgba(0, 0, 0, 0.12);
}

.segmented label + label span {
  border-left: 1px solid rgba(255, 255, 255, 0.25);
}

.segmented input:checked + span {
  background: linear-gradient(#9c9cf0, #6765d2);
}

.segmented input:focus-visible + span {
  outline: 2px solid #c3c2ff;
  outline-offset: -2px;
}

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 30px;
  font-size: 14.5px;
  letter-spacing: 0.03em;
  cursor: pointer;
}

.check input {
  appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  border: 1px solid #45464c;
  background: #f4f4f7;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.check input::after {
  content: '';
  width: 10px;
  height: 5px;
  border: solid var(--text);
  border-width: 0 0 2.5px 2.5px;
  transform: translateY(-1px) rotate(-45deg);
  opacity: 0;
}

.check input:checked::after {
  opacity: 1;
}

.check input:focus-visible {
  outline: 2px solid #c3c2ff;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 30px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  background: linear-gradient(#8e8f95, #6c6d73);
  color: #fff;
  letter-spacing: 0.04em;
}

.btn:hover:not(:disabled) {
  background: linear-gradient(#9a9ba1, #76777d);
}

.btn:disabled {
  opacity: 0.45;
}

.btn.attention {
  background: linear-gradient(#9c9cf0, #6765d2);
}

.btn.light {
  border-color: #a9a9b3;
  background: #f2f2f5;
  color: var(--text);
}

.btn.light:hover {
  background: #e2e1f5;
}

.credit {
  position: absolute;
  right: 14px;
  bottom: 5px;
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.08em;
  opacity: 0.75;
}

/* ----------------------------------------------------------------- 2D views */

.view2d {
  background: var(--foam);
}

.view2d svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
  cursor: grab;
}

.view2d svg.panning {
  cursor: grabbing;
}

.view2d svg.dragging,
.view2d svg.dragging * {
  cursor: grabbing !important;
}

.grid {
  fill: none;
  stroke: var(--grid);
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.fill {
  fill: var(--fill);
  stroke: none;
}

.curve {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.6;
  stroke-linejoin: round;
}

.polygon {
  fill: none;
  stroke: var(--ink-soft);
  stroke-width: 1.2;
}

.station .line {
  stroke: var(--station);
  stroke-width: 1.2;
}

.station .hit {
  stroke: transparent;
  stroke-width: 14;
}

.station {
  cursor: ns-resize;
}

.station:hover .line,
.station.active .line {
  stroke: var(--ink);
  stroke-width: 1.6;
}

.station-line {
  stroke: var(--station);
  stroke-width: 1;
  opacity: 0.55;
}

.station-mark {
  stroke: var(--station);
  stroke-width: 1;
  stroke-dasharray: 4 4;
  opacity: 0.7;
}

.section-label {
  fill: var(--muted);
  font-size: 12px;
  letter-spacing: 0.03em;
}

.handle .hit {
  fill: transparent;
}

.handle .dot {
  fill: var(--handle);
  stroke: var(--handle-edge);
  stroke-width: 1.5;
}

.handle {
  cursor: move;
}

.handle.vertical {
  cursor: ns-resize;
}

.handle:hover .dot {
  fill: #b4b3ff;
}

.handle.selected .dot {
  fill: #fff;
  stroke: var(--ink);
  stroke-width: 2.4;
}

circle.handle.locked {
  fill: var(--ink);
  pointer-events: none;
}

.readout {
  position: absolute;
  left: 10px;
  bottom: 8px;
  right: 120px;
  z-index: 2;
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--text);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.panel-side .readout {
  top: calc(var(--tab-h) + 6px);
  bottom: auto;
}

.view-tools {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.mini {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.6);
  background: linear-gradient(#8e8f95, #6c6d73);
  color: #fff;
  font-size: 12.5px;
}

.mini:hover {
  background: linear-gradient(#9c9ca2, #75767c);
}

.mini-seg {
  display: flex;
  border: 1px solid rgba(255, 255, 255, 0.6);
}

.mini-seg button {
  height: 26px;
  min-width: 32px;
  padding: 0 6px;
  border: 0;
  background: linear-gradient(#8e8f95, #6c6d73);
  color: #fff;
  font-size: 12.5px;
}

.mini-seg button + button {
  border-left: 1px solid rgba(255, 255, 255, 0.3);
}

.mini-seg button[aria-pressed='true'] {
  background: linear-gradient(#9c9cf0, #6765d2);
}

/* ------------------------------------------------------------------ dialogs */

.sheet {
  width: min(560px, calc(100vw - 32px));
  max-height: min(720px, calc(100vh - 48px));
  padding: 0;
  border: 1px solid var(--bevel);
  background: #d3d3d7;
  color: var(--text);
  box-shadow: 0 18px 60px rgba(10, 10, 30, 0.45);
}

.sheet[open] {
  display: flex;
  flex-direction: column;
}

.sheet::backdrop {
  background: rgba(30, 30, 40, 0.45);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 40px;
  padding: 0 6px 0 16px;
  background: linear-gradient(#a2a3a9, var(--chrome-hi));
  color: var(--on-chrome);
  flex: none;
}

.sheet-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.06em;
}

.sheet-close {
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 17px;
}

.sheet-close:hover {
  background: rgba(0, 0, 0, 0.12);
}

.sheet-body {
  padding: 6px 16px 14px;
  overflow: auto;
}

.sheet-body h3 {
  margin: 14px 0 8px;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.sheet-foot {
  padding: 12px 16px;
  border-top: 1px solid #bdbdc4;
  flex: none;
}

.board-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.board-list li {
  display: flex;
  gap: 4px;
}

.board-item {
  flex: 1;
  display: grid;
  grid-template-columns: 124px 1fr auto;
  align-items: center;
  gap: 14px;
  min-height: 48px;
  padding: 6px 12px 6px 8px;
  border: 1px solid #bfbfc6;
  background: #e9e9ed;
  text-align: left;
}

.board-item:hover {
  background: #f4f4fa;
  border-color: #9c9bd9;
}

.board-name {
  font-weight: 500;
  letter-spacing: 0.02em;
}

.board-dims {
  font-size: 12.5px;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.thumb {
  width: 120px;
  height: 30px;
}

.thumb path {
  fill: rgba(153, 153, 170, 0.5);
  stroke: var(--ink);
  stroke-width: 1;
}

.board-delete {
  flex: none;
  min-width: 44px;
  border: 1px solid #bfbfc6;
  background: #e9e9ed;
  color: var(--muted);
}

.board-delete:hover {
  color: var(--danger);
}

.board-delete.armed {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  padding: 0 10px;
}

.empty {
  margin: 0;
  padding: 12px;
  border: 1px dashed #aeaeb6;
  color: var(--muted);
}

.help dl {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 6px 16px;
  margin: 0;
  line-height: 1.4;
}

.help dt {
  font-weight: 500;
}

.help dd {
  margin: 0;
}

.help-note {
  margin: 16px 0 2px;
  color: var(--muted);
}

kbd {
  display: inline-block;
  min-width: 22px;
  padding: 0 5px;
  border: 1px solid #a5a5ae;
  border-bottom-width: 2px;
  border-radius: 3px;
  background: #f4f4f7;
  font: 500 12.5px/20px var(--font);
  text-align: center;
}

/* ------------------------------------------------------------ toast, boot */

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 50;
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 16px;
  background: var(--night);
  color: #f2f2f6;
  border-left: 3px solid #9d9cf5;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast[data-kind='error'] {
  border-left-color: #ff8a80;
}

.boot-note {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-content: center;
  gap: 4px;
  padding: 24px;
  max-width: 100%;
  background: var(--stage);
  text-align: center;
}

.boot-note[hidden] {
  display: none;
}

.boot-note h2 {
  margin: 0 0 6px;
  font-weight: 500;
}

.boot-note p {
  max-width: 58ch;
  margin: 4px auto;
  line-height: 1.5;
}

.boot-note code {
  padding: 1px 5px;
  background: #e8e8ec;
}

/* ------------------------------------------------------------- small screens */

@media (max-width: 1100px) {
  body {
    height: auto;
  }

  .workspace {
    grid-template-columns: minmax(0, 40fr) minmax(0, 60fr);
    grid-template-rows: 58vh 72vh 240px auto;
    grid-template-areas:
      'viewer viewer'
      'top sections'
      'side side'
      'params params';
  }

  .panel-params {
    min-height: 236px;
  }

  .design-name {
    max-width: 200px;
  }
}

@media (max-width: 720px) {
  .topbar {
    gap: 6px;
    padding: 0 6px 0 10px;
  }

  .brand span,
  .tb.labeled span,
  .tb .caret,
  .sep {
    display: none;
  }

  .design-name {
    min-width: 0;
  }

  .tb {
    min-width: 30px;
    padding: 0 6px;
  }

  .toolbar {
    bottom: 6px;
    gap: 2px;
  }

  .toolbar-left {
    left: 6px;
  }

  .toolbar-right {
    right: 6px;
  }

  .tool {
    width: 34px;
    height: 34px;
    font-size: 15px;
  }

  .tool-sep {
    width: 2px;
  }

  .groups {
    position: static;
    flex-direction: column;
    padding: calc(var(--tab-h) + 10px) 12px 30px;
  }

  .readout {
    right: 10px;
    bottom: 42px;
  }

  .board-item {
    grid-template-columns: 90px 1fr;
  }

  .board-dims {
    grid-column: 2;
    text-align: left;
  }

  .thumb {
    width: 90px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: none;
  }
}
