/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #080d1a;
  --bg2: #0d1428;
  --surface: rgba(255,255,255,0.04);
  --surface-hover: rgba(255,255,255,0.07);
  --border: rgba(255,255,255,0.08);
  --border-bright: rgba(255,255,255,0.15);
  --text: #e8eaf6;
  --text-muted: #7986a3;
  --text-dim: #4a5568;
  --col-a: #4FC3F7;
  --col-a-dim: rgba(79,195,247,0.15);
  --col-a-border: rgba(79,195,247,0.35);
  --col-b: #FFB74D;
  --col-b-dim: rgba(255,183,77,0.15);
  --col-b-border: rgba(255,183,77,0.35);
  --accent: #4FC3F7;
  --radius: 12px;
  --radius-sm: 8px;
  --panel-w: 340px;
  --header-h: 60px;
  --font: 'Inter', system-ui, sans-serif;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}

/* ===== SCROLLBAR — panel only ===== */
.input-panel::-webkit-scrollbar { width: 7px; }
.input-panel::-webkit-scrollbar-track { background: rgba(255,255,255,0.04); border-radius: 10px; }
.input-panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 10px; }
.input-panel::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.30); }

/* Generic (Firefox) */
.input-panel { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.2) rgba(255,255,255,0.04); }

/* ===== APP SHELL ===== */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ===== HEADER ===== */
.app-header {
  flex-shrink: 0;
  height: var(--header-h);
  background: linear-gradient(90deg, rgba(13,20,40,0.98) 0%, rgba(8,13,26,0.98) 100%);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  backdrop-filter: blur(12px);
  z-index: 10;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-controls {
  display: flex;
  align-items: center;
}

.lang-selector {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  outline: none;
}

.lang-selector:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--border-bright);
  color: var(--text);
}

.lang-selector option {
  background: #1a1e26;
  color: var(--text);
}

.header-icon {
  width: 40px;
  height: 40px;
  background: rgba(79,195,247,0.1);
  border: 1px solid var(--col-a-border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.header-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  background: linear-gradient(135deg, #e8eaf6 0%, #4FC3F7 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: 1px;
}

/* ===== LAYOUT ===== */
.layout {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ===== INPUT PANEL ===== */
.input-panel {
  width: var(--panel-w);
  flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding: 16px 14px 24px;
}

/* ===== SET CARDS ===== */
.set-card {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
  transition: border-color 0.2s;
  margin-bottom: 14px;
}

.set-card.set-a { border-top: 2px solid var(--col-a); }
.set-card.set-b { border-top: 2px solid var(--col-b); }

.set-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--surface-hover);
  border-bottom: 1px solid var(--border);
}

.set-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-a { background: var(--col-a); box-shadow: 0 0 8px rgba(79,195,247,0.5); }
.dot-b { background: var(--col-b); box-shadow: 0 0 8px rgba(255,183,77,0.5); }

.set-label {
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.set-name-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  text-align: right;
  min-width: 0;
}

/* ===== INPUT GROUPS ===== */
.input-group {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.input-group:last-child { border-bottom: none; }

.group-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  cursor: default;
}

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

.field-label {
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
  line-height: 1.3;
}

.field-label em {
  font-style: normal;
  color: var(--text-dim);
  font-size: 10px;
  margin-left: 2px;
}

.field input[type="number"] {
  width: 72px;
  padding: 5px 8px;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  text-align: right;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
  -moz-appearance: textfield;
}

.set-a .field input[type="number"]:focus {
  border-color: var(--col-a-border);
  background: var(--col-a-dim);
}

.set-b .field input[type="number"]:focus {
  border-color: var(--col-b-border);
  background: var(--col-b-dim);
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }

/* ===== CONTROLS ===== */
.controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.btn-primary {
  width: 100%;
  padding: 11px;
  background: linear-gradient(135deg, #1a6fa8 0%, #0d4f7c 100%);
  border: 1px solid rgba(79,195,247,0.4);
  border-radius: var(--radius-sm);
  color: #e8f7ff;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.3px;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #1f80c4 0%, #0f5e96 100%);
  border-color: var(--col-a);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(79,195,247,0.2);
}

.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  width: 100%;
  padding: 9px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  border-color: var(--border-bright);
  color: var(--text);
  background: var(--surface);
}

/* ===== LEGEND ===== */
.legend {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 14px;
}

.legend-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.legend-items {
  display: flex;
  gap: 16px;
  margin-bottom: 10px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.legend-icons { display: flex; flex-direction: column; gap: 5px; }

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.legend-line {
  display: inline-block;
  width: 24px;
  height: 2px;
  border-radius: 2px;
}

.legend-line.solid { background: #aaa; }
.legend-line.dashed {
  background: transparent;
  border-top: 2px dashed #666;
}
.legend-line.foot { background: #aaa; height: 3px; }

/* ===== WARNING ===== */
.warning-box {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 11px;
  color: #fca5a5;
  line-height: 1.5;
}

.warning-box.hidden { display: none; }

/* ===== CANVAS AREA ===== */
.canvas-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

#diagramCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

#diagramCanvas:active { cursor: grabbing; }

.canvas-hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--text-dim);
  background: rgba(8,13,26,0.7);
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  backdrop-filter: blur(6px);
  pointer-events: none;
  white-space: nowrap;
}

/* ===== SUMMARY PANEL ===== */
.summary-panel {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(13, 20, 40, 0.6);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  min-width: 120px;
  text-align: right;
}

.summary-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.summary-label {
  font-size: 9px;
  font-weight: 600;
  color: var(--col-b);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  opacity: 0.9;
}

.summary-value {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ===== VISIBILITY TOGGLE BUTTON ===== */
.vis-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: color 0.18s, background 0.18s, border-color 0.18s;
  padding: 0;
}

.vis-toggle:hover {
  color: var(--text);
  background: rgba(255,255,255,0.07);
  border-color: var(--border);
}

.eye-icon {
  width: 16px;
  height: 16px;
  display: block;
}

/* Show eye-open by default, hide eye-closed */
.vis-toggle .eye-closed { display: none; }
.vis-toggle .eye-open  { display: block; }

/* When set is hidden: show eye-closed, dim the dot, mute the button */
.set-card.set-hidden .vis-toggle { color: var(--text-dim); }
.set-card.set-hidden .vis-toggle .eye-open  { display: none; }
.set-card.set-hidden .vis-toggle .eye-closed { display: block; }
.set-card.set-hidden .set-dot { opacity: 0.3; }

/* ===== COLLAPSIBLE SET BODY ===== */
.set-header {
  cursor: pointer;
  user-select: none;
}

.chevron {
  width: 16px;
  height: 16px;
  color: var(--text-dim);
  flex-shrink: 0;
  transition: transform 0.25s ease;
}

.set-header[aria-expanded="false"] .chevron {
  transform: rotate(-90deg);
}

/* Grid-rows trick: animates height without overflow:hidden */
.set-body {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.28s ease, opacity 0.22s ease;
  opacity: 1;
}

.set-body.collapsed {
  grid-template-rows: 0fr;
  opacity: 0;
}

/* Inner wrapper needed for the grid trick */
.set-body-inner {
  overflow: hidden; /* only clips the shrinking content, not the outer panel */
}

/* ===== TOOLTIP ===== */
.tooltip {
  position: fixed;
  z-index: 1000;
  width: 240px;
  background: rgba(13, 20, 40, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-bright);
  border-radius: 10px;
  padding: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tooltip.hidden {
  opacity: 0;
  transform: translateY(10px);
  display: none;
}

.tooltip-illustration {
  width: 100%;
  height: 100px;
  background: rgba(255,255,255,0.03);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.tooltip-illustration svg {
  width: 100%;
  height: 100%;
  padding: 10px;
}

.tooltip-text {
  font-size: 11px;
  line-height: 1.4;
  color: var(--text-muted);
}

.field-label[data-tooltip] {
  cursor: help;
}

.field-label[data-tooltip]:hover {
  color: var(--text);
  text-decoration-color: var(--accent);
}

.author-info {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 400;
  margin-left: 8px;
  vertical-align: middle;
}

/* ===== ANIMATION PANEL ===== */
.animation-panel {
  position: absolute;
  bottom: 20px;
  left: 20px;
  background: rgba(13, 20, 40, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  display: flex;
  gap: 20px;
  align-items: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  z-index: 100;
}

.mod-wheel-container {
  display: flex;
  align-items: center;
}

.mod-wheel {
  appearance: none;
  -webkit-appearance: none;
  width: 120px;
  height: 24px;
  background: rgba(0,0,0,0.5);
  border-radius: 12px;
  outline: none;
  border: 1px solid var(--border);
  box-shadow: inset 0 2px 5px rgba(0,0,0,0.5);
}

.mod-wheel::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  cursor: grab;
  box-shadow: 0 0 8px rgba(79, 195, 247, 0.5);
}

.mod-wheel::-webkit-slider-thumb:active {
  cursor: grabbing;
}

.clock-input-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.clock-input-group label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.clock-input-group input {
  width: 50px;
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  text-align: center;
}

#btnResetPedal {
  padding: 4px 10px;
  font-size: 11px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s;
}

#btnResetPedal:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.mobile-set-buttons,
.mobile-panel-header {
  display: none;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  :root { --panel-w: 100%; }
  
  .app {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }
  
  .app-header {
    height: auto;
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 12px;
  }
  
  .header-inner {
    width: 100%;
  }

  .header-title {
    font-size: 15px;
    line-height: 1.2;
  }
  
  .author-info {
    display: block;
    margin-left: 0;
    margin-top: 2px;
  }

  .layout { 
    flex-direction: column; 
  }
  
  .canvas-area { 
    order: -1; 
    flex: 1; 
    height: auto; 
    position: relative;
    z-index: 10; 
  }
  
  .input-panel { 
    display: none;
    width: 100%; 
    max-height: none; 
    border-right: none; 
    overflow-y: auto;
    padding: 16px;
    z-index: 1000;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg2);
  }

  body.mobile-panel-open .input-panel {
    display: block;
  }

  body.mobile-panel-open {
    overflow: hidden;
  }

  .mobile-set-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
  }

  .mobile-set-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: rgba(13, 20, 40, 0.85);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  }

  .mobile-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
  }

  .mobile-panel-title {
    font-size: 16px;
    font-weight: 600;
  }
  
  .mobile-close-btn {
    padding: 6px 12px;
  }

  .animation-panel {
    position: fixed;
    bottom: 10px;
    left: 10px;
    right: 10px;
    padding: 8px 12px;
    justify-content: space-between;
    gap: 8px;
    z-index: 50;
  }
  
  .mod-wheel-container {
    flex: 1;
  }
  
  .mod-wheel {
    width: 100%;
  }

  .clock-input-group {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .canvas-hint {
    display: none; 
  }

  .summary-panel {
    top: 10px;
    right: 10px;
    padding: 6px 10px;
  }
  
  .summary-value {
    font-size: 11px;
  }
}
