/* styles.css */
:root {
  --ink: #0a0a0a;
  --white: #ffffff;
  --gray-60: #5a5a5a;
  --gray-30: #c7c7c7;
  --gray-08: #f3f3f3;
  --bg: var(--white);
  --fg: var(--ink);
  --fg-secondary: var(--ink);
  --border: var(--gray-30);
  --border-strong: var(--ink);
  --surface: var(--gray-08);
  --font-content: Cambria, Georgia, "Times New Roman", serif;
  --font-ui: Arial, Helvetica, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, monospace;
  --text-display: 34px;
  --text-h1: 26px;
  --text-h2: 21px;
  --text-body: 15px;
  --text-ui: 14px;
  --text-label: 12px;
  --text-code: 12.5px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --radius-input: 2px;
  --intensity-color: #ff7926;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: var(--text-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  overflow: hidden;
}

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

button,
select,
input {
  border-radius: var(--radius-input);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
.intensity-rail:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  border-right: 1px solid var(--border-strong);
  background: var(--white);
  scrollbar-width: thin;
}

.brand {
  padding: var(--space-6) var(--space-6) var(--space-5);
  border-bottom: 1px solid var(--border-strong);
}

.brand-kicker,
.section-kicker,
.field-label,
.tiny-label {
  display: block;
  margin: 0 0 var(--space-2);
  color: var(--fg-secondary);
  font-size: var(--text-label);
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.2;
  text-transform: uppercase;
}

.brand h1 {
  margin: 0;
  font-family: var(--font-content);
  font-size: 30px;
  line-height: 1.05;
}

.brand p {
  margin: var(--space-3) 0 0;
  color: var(--fg-secondary);
  font-size: var(--text-body);
}

.sidebar-section {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.section-heading h2 {
  margin: 0;
  font-family: var(--font-content);
  font-size: var(--text-h2);
  line-height: 1.15;
}

.section-heading span {
  color: var(--fg-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-code);
}

.field {
  margin-bottom: var(--space-4);
}

.field:last-child {
  margin-bottom: 0;
}

.text-input,
.number-input,
.select-input {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  background: var(--white);
}

.field-help {
  margin: var(--space-2) 0 0;
  color: var(--fg-secondary);
  font-size: 13px;
  line-height: 1.35;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--border-strong);
}

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

.segmented-control label {
  min-height: 38px;
  padding: 8px 10px;
  background: var(--white);
  cursor: pointer;
  font-size: var(--text-ui);
  text-align: center;
}

.segmented-control label + input + label {
  border-left: 1px solid var(--border-strong);
}

.segmented-control input:checked + label {
  background: var(--ink);
  color: var(--white);
}

.segmented-control input:focus-visible + label {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.band-map {
  display: grid;
  gap: 6px;
  padding: var(--space-3);
  border: 1px solid var(--border);
  background: var(--surface);
}

.band-row {
  display: grid;
  gap: 6px;
}

.band-row-three {
  grid-template-columns: repeat(3, 1fr);
  padding: 0 18px;
}

.band-row-four {
  grid-template-columns: repeat(4, 1fr);
}

.channel-toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.channel-toggle label {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-strong);
  background: var(--white);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: var(--text-code);
}

.channel-toggle input:checked + label {
  background: var(--ink);
  color: var(--white);
}

.channel-toggle input:focus-visible + label {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.reference-field {
  grid-column: 1 / -1;
}

.button {
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  background: var(--white);
  cursor: pointer;
  font-size: var(--text-ui);
  font-weight: 700;
}

.button:hover {
  background: var(--ink);
  color: var(--white);
}

.button-primary {
  background: var(--ink);
  color: var(--white);
}

.button-primary:hover {
  opacity: 0.85;
}

.button:disabled {
  cursor: default;
  opacity: 0.42;
}

.button:disabled:hover {
  background: inherit;
  color: inherit;
}

.button-full {
  width: 100%;
}

.study-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: var(--space-4) 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.summary-stat {
  padding: var(--space-3) 0;
}

.summary-stat + .summary-stat {
  padding-left: var(--space-3);
  border-left: 1px solid var(--border);
}

.summary-stat strong {
  display: block;
  font-family: var(--font-content);
  font-size: var(--text-h1);
  line-height: 1;
}

.summary-stat span {
  color: var(--fg-secondary);
  font-size: 13px;
}

.intensity-panel {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: var(--space-4);
  align-items: stretch;
}

.intensity-rail-wrap {
  position: relative;
  width: 74px;
  height: 230px;
}

.intensity-rail {
  position: absolute;
  inset: 0 17px;
  border: 1px solid var(--border-strong);
  background: linear-gradient(to bottom, #ffe600 0%, #ffc51b 27%, #ff7926 50%, #e93d1c 73%, #a70f0a 100%);
  cursor: pointer;
  touch-action: none;
}

.intensity-thumb {
  position: absolute;
  left: -9px;
  width: 50px;
  height: 2px;
  background: var(--ink);
  pointer-events: none;
}

.intensity-thumb::before,
.intensity-thumb::after {
  position: absolute;
  top: -4px;
  width: 8px;
  height: 10px;
  background: var(--white);
  border: 1px solid var(--ink);
  content: "";
}

.intensity-thumb::before {
  left: -1px;
}

.intensity-thumb::after {
  right: -1px;
}

.intensity-copy {
  position: relative;
  min-height: 230px;
}

.intensity-label {
  position: absolute;
  left: 0;
  font-size: var(--text-ui);
  line-height: 1.2;
}

.intensity-label strong {
  display: block;
  font-family: var(--font-content);
  font-size: var(--text-h2);
}

.intensity-label-top {
  top: 0;
}

.intensity-label-middle {
  top: 50%;
  transform: translateY(-50%);
}

.intensity-label-bottom {
  bottom: 0;
}

.intensity-readout {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: var(--text-code);
}

.color-chip {
  width: 22px;
  height: 22px;
  border: 1px solid var(--border-strong);
  background: var(--intensity-color);
}

.tool-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.tool-button.active {
  background: var(--ink);
  color: var(--white);
}

.sequence-list {
  display: grid;
  max-height: 224px;
  overflow-y: auto;
  border-top: 1px solid var(--border-strong);
}

.sequence-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: var(--space-2);
  align-items: center;
  min-height: 42px;
  padding: 7px 4px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: var(--white);
  cursor: pointer;
  text-align: left;
}

.sequence-item:hover,
.sequence-item.current {
  background: var(--surface);
}

.sequence-number,
.sequence-pair {
  font-family: var(--font-mono);
  font-size: var(--text-code);
}

.sequence-state {
  width: 8px;
  height: 8px;
  border: 1px solid var(--ink);
  border-radius: 50%;
}

.sequence-item.done .sequence-state {
  background: var(--ink);
}

.sequence-item.reference {
  border-top: 1px solid var(--border-strong);
  font-weight: 700;
}

.sidebar-footer {
  padding: var(--space-4) var(--space-6) var(--space-6);
  color: var(--fg-secondary);
  font-size: var(--text-code);
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
}

.workspace-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: var(--space-4);
  align-items: center;
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border-strong);
  background: var(--white);
}

.pair-heading {
  min-width: 0;
}

.pair-heading h2 {
  margin: 0;
  overflow: hidden;
  font-family: var(--font-content);
  font-size: var(--text-h1);
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pair-heading p {
  margin: 2px 0 0;
  color: var(--fg-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-code);
}

.polarity-group {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
}

.polarity-group[hidden] {
  display: none;
}

.polarity-badge {
  display: inline-flex;
  min-height: 31px;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border: 1px solid var(--border-strong);
  background: var(--white);
  font-size: 13px;
}

.polarity-badge strong {
  font-family: var(--font-mono);
}

.hand-stage {
  position: relative;
  display: flex;
  min-height: 0;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: var(--space-6);
}

.hand-stage::before {
  content: "";
  position: absolute;
  inset: -50%;
  width: 200%;
  height: 200%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='28'%3E%3Ctext x='0' y='20' font-family='Arial,Helvetica,sans-serif' font-size='14' font-weight='700' letter-spacing='0.1em' fill='%23000' opacity='0.07'%3ELEONARDO M FERRISI ~ LEONARDO M FERRISI ~%3C/text%3E%3C/svg%3E");
  background-repeat: repeat;
  transform: rotate(-45deg);
  pointer-events: none;
  z-index: 0;
}

.hand-board {
  position: relative;
  z-index: 1;
  display: flex;
  width: min(100%, 740px);
  height: 100%;
  min-height: 0;
  max-height: 790px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-strong);
  background: var(--white);
}

#hand-svg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: 760px;
  cursor: crosshair;
}

.hand-region {
  fill: var(--white);
  cursor: crosshair;
}

.hand-region:hover {
  filter: brightness(0.94);
}

.hand-outline,
.hand-detail {
  fill: none;
  stroke: #231f20;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.hand-outline {
  stroke-width: 0.5;
}

.hand-detail {
  stroke-width: 0.1;
}

.hand-miter {
  stroke-linecap: butt;
  stroke-linejoin: miter;
  stroke-miterlimit: 10;
}

.completion-panel {
  position: absolute;
  inset: var(--space-8);
  z-index: 2;
  display: none;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-strong);
  background: var(--white);
  text-align: center;
}

.completion-panel.show {
  display: flex;
}

.completion-content {
  width: min(480px, 100%);
  padding: var(--space-8);
}

.completion-content h2 {
  margin: 0;
  font-family: var(--font-content);
  font-size: var(--text-display);
}

.completion-content p {
  margin: var(--space-3) 0 var(--space-6);
  color: var(--fg-secondary);
}

.completion-actions {
  display: flex;
  justify-content: center;
  gap: var(--space-2);
}

.workspace-footer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: var(--space-4);
  align-items: center;
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-strong);
  background: var(--white);
}

.footer-left,
.footer-right {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.footer-right {
  justify-content: flex-end;
}

.autosave-status {
  color: var(--fg-secondary);
  font-size: var(--text-code);
  text-align: center;
}

.autosave-status strong {
  color: var(--fg);
}

.toast {
  position: fixed;
  right: var(--space-5);
  bottom: var(--space-5);
  z-index: 5;
  max-width: 340px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  background: var(--ink);
  color: var(--white);
  font-size: var(--text-ui);
  opacity: 0;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
}

@media (min-width: 901px) and (max-width: 1200px) {
  .workspace-header {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .polarity-group {
    grid-column: 1 / -1;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .workspace-footer {
    grid-template-columns: auto minmax(0, 1fr);
    gap: var(--space-3);
  }

  .autosave-status {
    grid-column: 1 / -1;
    grid-row: 1;
  }
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: visible;
  }

  .sidebar {
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border-strong);
  }

  .workspace {
    height: auto;
    min-height: 760px;
    overflow: visible;
  }

  .workspace-header {
    grid-template-columns: auto 1fr;
  }

  .polarity-group {
    grid-column: 1 / -1;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .hand-stage {
    min-height: 600px;
  }

  .workspace-footer {
    grid-template-columns: 1fr 1fr;
  }

  .autosave-status {
    grid-column: 1 / -1;
    grid-row: 1;
  }
}

.license-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
}

.license-overlay.show {
  display: flex;
}

.license-modal {
  width: min(620px, calc(100% - 32px));
  max-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-strong);
  background: var(--white);
}

.license-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}

.license-modal-header h3 {
  margin: 0;
  font-family: var(--font-content);
  font-size: var(--text-h2);
}

.license-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5);
  font-family: var(--font-mono);
  font-size: var(--text-code);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-5);
  background: var(--white);
  transition: opacity 0.5s ease;
}

.loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loading-screen img {
  width: 120px;
  height: 120px;
  animation: loading-pulse 1.8s ease-in-out infinite;
}

.loading-screen p {
  margin: 0;
  color: var(--fg-secondary);
  font-family: var(--font-ui);
  font-size: var(--text-ui);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 700;
}

@keyframes loading-pulse {
  0%, 100% { opacity: 0.4; transform: scale(0.96); }
  50% { opacity: 1; transform: scale(1); }
}

@media (max-width: 560px) {
  .workspace-header,
  .workspace-footer,
  .hand-stage {
    padding: var(--space-3);
  }

  .workspace-footer {
    grid-template-columns: 1fr;
  }

  .footer-left,
  .footer-right {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .autosave-status {
    grid-column: auto;
  }

  .completion-panel {
    inset: var(--space-3);
  }

  .completion-actions {
    flex-direction: column;
  }
}
