/* ═══════════════════════════════════════════════════════════════
   Circle Theorem Explorer — App-Specific Styles
   Prefix: ct-
   ═══════════════════════════════════════════════════════════════ */

/* ── Colour tokens ────────────────────────────────────────────── */
:root {
  --ct-circle:              #334155;
  --ct-line-primary:        #1e3a8a;
  --ct-line-construction:   #be185d;
  --ct-line-chord:          #dc2626;
  --ct-arc-major:           #9f1239;
  --ct-arc-minor:           #166534;
  --ct-angle-fill:          rgba(59, 130, 246, 0.18);
  --ct-angle-fill-centre:   rgba(190, 24, 93, 0.15);
  --ct-angle-stroke:        #3b82f6;
  --ct-angle-stroke-centre: #be185d;
  --ct-point:               #1e3a8a;
  --ct-point-hover:         #3b82f6;
  --ct-centre:              #475569;
  --ct-label:               #1e3a8a;
  --ct-label-centre:        #be185d;
  --ct-isosceles-tick:      #be185d;
  --ct-segment-fill:        rgba(59, 130, 246, 0.06);
}

[data-theme="dark"] {
  --ct-circle:              #94a3b8;
  --ct-line-primary:        #60a5fa;
  --ct-line-construction:   #f472b6;
  --ct-line-chord:          #f87171;
  --ct-arc-major:           #fb7185;
  --ct-arc-minor:           #4ade80;
  --ct-angle-fill:          rgba(96, 165, 250, 0.2);
  --ct-angle-fill-centre:   rgba(244, 114, 182, 0.18);
  --ct-angle-stroke:        #60a5fa;
  --ct-angle-stroke-centre: #f472b6;
  --ct-point:               #60a5fa;
  --ct-point-hover:         #93c5fd;
  --ct-centre:              #cbd5e1;
  --ct-label:               #93c5fd;
  --ct-label-centre:        #f9a8d4;
  --ct-isosceles-tick:      #f472b6;
  --ct-segment-fill:        rgba(96, 165, 250, 0.1);
}


/* ── Layout ───────────────────────────────────────────────────── */
.ct-layout {
  display: flex;
  height: calc(100vh - var(--sm-top-offset, 26px));
  overflow: hidden;
  background: var(--sm-canvas-bg);
}

.ct-svg-area {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  overflow: hidden;
}

.ct-svg-area svg {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}


/* ── Panel ────────────────────────────────────────────────────── */
.ct-panel {
  width: 280px;
  flex-shrink: 0;
  overflow: hidden;
  border-right: 1px solid var(--sm-border);
  background: var(--sm-surface);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ct-sheet-toggle {
  display: none;
  align-items: center;
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
}

/* Sheet handle is mobile-only; never show on desktop/tablet landscape layouts */
@media (min-width: 681px) {
  .ct-sheet-toggle {
    display: none !important;
  }
}

.ct-sheet-label-expanded {
  display: none;
  flex: 1;
  min-width: 0;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--sm-text-muted);
  text-align: left;
}

.ct-panel-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.ct-sheet-summary {
  flex: 1;
  min-width: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--sm-text);
  text-align: left;
}

.ct-sheet-grip {
  width: 40px;
  height: 5px;
  border-radius: 3px;
  background: var(--sm-border);
  flex-shrink: 0;
}

.ct-sheet-chevron {
  flex-shrink: 0;
  font-size: 0.6rem;
  color: var(--sm-text-muted);
  transition: transform var(--sm-transition, 0.2s ease);
}

.ct-locked-select {
  opacity: 0.72;
  cursor: not-allowed;
}

.ct-t3-locked-hint {
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--sm-text-muted);
  padding: 8px 10px;
  margin-top: 4px;
  border-radius: 6px;
  background: var(--sm-bg);
}

.ct-selector {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.ct-selector .ct-select {
  flex: 1;
  min-width: 0;
  width: auto;
}

.ct-theorem-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--sm-indigo);
  color: #fff;
  font-weight: 700;
  font-size: 0.75rem;
  flex-shrink: 0;
}

.ct-theorem-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--sm-text);
  line-height: 1.2;
}

.ct-statement {
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--sm-indigo);
  font-weight: 400;
  padding: 10px 12px;
  background: var(--sm-indigo-light);
  border-radius: 8px;
  border-left: 3px solid var(--sm-indigo);
}

[data-theme="dark"] .ct-statement {
  background: rgba(79, 70, 229, 0.12);
}

.ct-angles {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ct-angle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.85rem;
}

.ct-angle-row.ct-inscribed {
  background: rgba(59, 130, 246, 0.08);
  border-left: 3px solid var(--ct-angle-stroke);
}

.ct-angle-row.ct-central {
  background: rgba(190, 24, 93, 0.06);
  border-left: 3px solid var(--ct-angle-stroke-centre);
}

[data-theme="dark"] .ct-angle-row.ct-inscribed {
  background: rgba(96, 165, 250, 0.1);
}

[data-theme="dark"] .ct-angle-row.ct-central {
  background: rgba(244, 114, 182, 0.1);
}

.ct-angle-row .katex {
  font-size: 1em;
}

.ct-relationship {
  font-size: 0.78rem;
  color: var(--sm-text-muted);
  padding: 4px 10px;
  font-style: italic;
}

.ct-divider {
  height: 1px;
  background: var(--sm-border);
  margin: 2px 0;
}

/* ── Connections section ──────────────────────────────────────── */
.ct-connections-header {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--sm-text-muted);
  padding: 4px 0 6px;
}

.ct-connection-link {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 6px 10px;
  border-radius: 6px;
  font-family: var(--sm-font);
  font-size: 0.78rem;
  color: var(--sm-indigo);
  cursor: pointer;
  line-height: 1.4;
  transition: background 0.15s ease;
}

.ct-connection-link:hover {
  background: var(--sm-indigo-light);
}

[data-theme="dark"] .ct-connection-link:hover {
  background: rgba(79, 70, 229, 0.12);
}

.ct-cross-hint {
  margin-top: 4px;
  font-style: italic;
  opacity: 0.85;
}


/* ── Toggles ──────────────────────────────────────────────────── */
.ct-toggles {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ct-toggles .sm-toggle {
  font-size: 0.8rem;
}


/* ── SVG elements ─────────────────────────────────────────────── */

/* Points: visible circle + invisible hit area */
.ct-point {
  cursor: grab;
}
.ct-point:active {
  cursor: grabbing;
}
.ct-point-visible {
  fill: var(--ct-point);
  stroke: var(--sm-canvas-bg);
  stroke-width: 2;
  pointer-events: none;
}
.ct-point-hit {
  fill: transparent;
  stroke: none;
  cursor: grab;
}
.ct-point-hit:active {
  cursor: grabbing;
}
.ct-point-centre .ct-point-visible {
  fill: var(--ct-centre);
  r: 4;
}

/* Point labels */
.ct-point-label {
  font-family: var(--sm-font);
  font-size: 15px;
  font-weight: 600;
  fill: var(--ct-label);
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: central;
}
.ct-point-label-centre {
  fill: var(--ct-centre);
  font-size: 14px;
}

/* Lines */
.ct-line-primary {
  stroke: var(--ct-line-primary);
  stroke-width: 2.2;
  stroke-linecap: round;
  fill: none;
}
.ct-line-construction {
  stroke: var(--ct-line-construction);
  stroke-width: 1.8;
  stroke-linecap: round;
  fill: none;
}
.ct-line-construction-dashed {
  stroke: var(--ct-line-construction);
  stroke-width: 1.6;
  stroke-dasharray: 8 6;
  stroke-linecap: round;
  fill: none;
}
.ct-line-chord {
  stroke: var(--ct-line-chord);
  stroke-width: 1.6;
  stroke-dasharray: 8 6;
  stroke-linecap: round;
  fill: none;
}

/* Circle and arcs */
.ct-circle {
  fill: none;
  stroke: var(--ct-circle);
  stroke-width: 1.8;
}
.ct-arc-major {
  fill: none;
  stroke: var(--ct-arc-major);
  stroke-width: 3.5;
  stroke-linecap: round;
}
.ct-arc-minor {
  fill: none;
  stroke: var(--ct-arc-minor);
  stroke-width: 3.5;
  stroke-linecap: round;
}

/* Angle arcs */
.ct-angle-arc {
  fill: var(--ct-angle-fill);
  stroke: var(--ct-angle-stroke);
  stroke-width: 1.5;
}
.ct-angle-arc-centre {
  fill: var(--ct-angle-fill-centre);
  stroke: var(--ct-angle-stroke-centre);
  stroke-width: 1.5;
}

/* Angle value labels in diagram */
.ct-angle-label {
  font-family: var(--sm-font);
  font-size: 13px;
  font-weight: 600;
  fill: var(--ct-label);
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: central;
}
.ct-angle-label-centre {
  fill: var(--ct-label-centre);
}

.ct-angle-label--algebraic {
  font-style: italic;
  font-weight: 600;
}

.ct-angle-label--long {
  font-size: 0.85em;
}

/* Isosceles tick marks */
.ct-tick {
  stroke: var(--ct-isosceles-tick);
  stroke-width: 1.8;
  stroke-linecap: round;
  fill: none;
}

/* Transitions for toggled elements */
.ct-fadeable {
  transition: opacity 0.25s ease;
}
.ct-hidden {
  opacity: 0;
  pointer-events: none;
}

/* ── Construction line draw-in animation ─────────────────────── */

/* Solid construction lines: draw in via stroke-dashoffset */
.ct-line-construction {
  stroke-dasharray: 1000;
  stroke-dashoffset: 1000;
  transition: stroke-dashoffset 0.35s ease-out, opacity 0.25s ease;
}

.ct-fadeable:not(.ct-hidden) .ct-line-construction,
:not(.ct-fadeable) > .ct-line-construction {
  stroke-dashoffset: 0;
}

.ct-fadeable.ct-hidden .ct-line-construction {
  stroke-dashoffset: 1000;
}

/* Dashed construction lines: draw in too (dasharray is overridden for the animation) */
.ct-line-construction-dashed {
  stroke-dasharray: 1000;
  stroke-dashoffset: 1000;
  transition: stroke-dashoffset 0.35s ease-out, opacity 0.25s ease;
}

.ct-fadeable:not(.ct-hidden) .ct-line-construction-dashed {
  stroke-dashoffset: 0;
}

.ct-fadeable.ct-hidden .ct-line-construction-dashed {
  stroke-dashoffset: 1000;
}

/* When draw-in finishes, restore the actual dash pattern for dashed lines */
.ct-fadeable:not(.ct-hidden) .ct-line-construction-dashed {
  transition: stroke-dashoffset 0.35s ease-out, opacity 0.25s ease, stroke-dasharray 0s 0.35s;
  stroke-dasharray: 8 6;
}

/* Dashed chord lines: fade only, no draw-in (they use dasharray for their pattern) */
.ct-fadeable .ct-line-chord {
  transition: opacity 0.25s ease;
}

/* ── Angle arc scale-in ──────────────────────────────────────── */

/* All toggled angle arcs (both inscribed and centre) scale in from zero */
.ct-angle-arc.ct-fadeable,
.ct-angle-arc-centre.ct-fadeable {
  transition: opacity 0.25s ease, transform 0.3s ease;
}

.ct-angle-arc.ct-fadeable.ct-hidden,
.ct-angle-arc-centre.ct-fadeable.ct-hidden {
  transform: scale(0);
  opacity: 0;
}

.ct-angle-arc.ct-fadeable:not(.ct-hidden),
.ct-angle-arc-centre.ct-fadeable:not(.ct-hidden) {
  transform: scale(1);
}


/* ── Theorem selector dropdown ────────────────────────────────── */
.ct-select {
  width: 100%;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--sm-border);
  background: var(--sm-surface);
  color: var(--sm-text);
  font-family: var(--sm-font);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236366f1' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.ct-select:focus {
  outline: 2px solid var(--sm-indigo);
  outline-offset: 1px;
}


/* ── Enlarge (classroom projection) ───────────────────────────── */
.ct-enlarge-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--sm-text-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  font-family: var(--sm-font);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--sm-transition, 0.15s ease), color var(--sm-transition, 0.15s ease);
}

.ct-enlarge-btn:hover {
  background: var(--sm-border);
  color: var(--sm-text);
}

.ct-enlarge-btn:focus-visible {
  outline: 2px solid var(--sm-indigo);
  outline-offset: 2px;
}

.ct-enlarge-overlay {
  display: none;
  z-index: 400;
  box-sizing: border-box;
}

.ct-enlarge-overlay.ct-enlarge-overlay--open {
  display: block;
  position: fixed;
  left: 0;
  top: var(--sm-top-offset, 26px);
  width: min(50vw, 520px);
  height: calc(100vh - var(--sm-top-offset, 26px));
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
  -webkit-overflow-scrolling: touch;
  background: transparent;
}

.ct-enlarge-content {
  position: relative;
  background: var(--sm-surface);
  border: 1px solid var(--sm-border);
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
  padding: 24px 28px;
}

[data-theme="dark"] .ct-enlarge-content {
  box-shadow: 0 4px 28px rgba(0, 0, 0, 0.45);
}

.ct-enlarge-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--sm-text-muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  font-family: var(--sm-font);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ct-enlarge-close:hover {
  background: var(--sm-border);
  color: var(--sm-text);
}

.ct-enlarge-close:focus-visible {
  outline: 2px solid var(--sm-indigo);
  outline-offset: 2px;
}

.ct-enlarge-statement {
  font-size: 1.4rem;
  line-height: 1.55;
  color: var(--sm-indigo);
  font-weight: 400;
  /* Left: gap past accent border; right: clear the absolutely positioned close control */
  padding: 14px 52px 14px 18px;
  margin-bottom: 12px;
  background: var(--sm-indigo-light);
  border-radius: 8px;
  border-left: 3px solid var(--sm-indigo);
  box-sizing: border-box;
}

[data-theme="dark"] .ct-enlarge-statement {
  background: rgba(79, 70, 229, 0.12);
}

.ct-enlarge-angles {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ct-enlarge-angles .ct-angle-row {
  font-size: 1.6rem;
  padding: 12px 16px 12px 18px;
  box-sizing: border-box;
}

.ct-enlarge-angles .ct-angle-row .katex {
  font-size: 1.6em;
}

.ct-enlarge-relationship {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.ct-enlarge-relationship .ct-relationship,
.ct-enlarge-relationship .ct-t3-locked-hint {
  font-size: 1.38rem;
  line-height: 1.55;
  padding-left: 14px;
  padding-right: 14px;
  box-sizing: border-box;
}

.ct-enlarge-relationship .ct-connection-link {
  font-size: 1.05rem;
}

.ct-enlarge-divider {
  height: 1px;
  background: var(--sm-border);
  margin: 16px 0 12px;
}

.ct-enlarge-toggles {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ct-enlarge-toggles .sm-toggle {
  font-size: 0.85rem;
}

@media (max-width: 680px) {
  .ct-enlarge-overlay.ct-enlarge-overlay--open {
    display: flex;
    align-items: center;
    justify-content: center;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: auto;
    padding: 12px;
    background: rgba(0, 0, 0, 0.4);
  }

  [data-theme="dark"] .ct-enlarge-overlay.ct-enlarge-overlay--open {
    background: rgba(0, 0, 0, 0.6);
  }

  .ct-enlarge-content {
    width: 100%;
    max-width: 520px;
    max-height: min(88vh, 640px);
    overflow-y: auto;
    margin: auto;
  }
}


/* ── Classroom mode (larger panel text) ───────────────────────── */
.ct-panel.ct-classroom .ct-statement {
  font-size: 1.15rem;
  padding: 14px 16px;
  line-height: 1.6;
}

.ct-panel.ct-classroom .ct-angle-row {
  font-size: 1.1rem;
  padding: 8px 12px;
}

.ct-panel.ct-classroom .ct-angle-row .katex {
  font-size: 1.15em;
}

.ct-panel.ct-classroom .ct-relationship {
  font-size: 1rem;
}

.ct-panel.ct-classroom .ct-toggles .sm-toggle {
  font-size: 0.82rem;
}

.ct-panel.ct-classroom {
  width: 360px;
}

.ct-classroom-heading .ct-theorem-title {
  flex: 1;
  min-width: 0;
}

@media (max-width: 900px) {
  .ct-panel.ct-classroom {
    width: 300px;
  }
}


/* ── Second angle colour (T4 cyclic quad, second pair) ────────── */
:root {
  --ct-angle-fill-2:   rgba(16, 185, 129, 0.18);
  --ct-angle-stroke-2: #059669;
}

[data-theme="dark"] {
  --ct-angle-fill-2:   rgba(52, 211, 153, 0.2);
  --ct-angle-stroke-2: #34d399;
}

.ct-angle-arc-2 {
  fill: var(--ct-angle-fill-2);
  stroke: var(--ct-angle-stroke-2);
  stroke-width: 1.5;
}

/* T4 panel rows for the B/D (teal) pair */
.ct-angle-row.ct-inscribed-2 {
  background: rgba(16, 185, 129, 0.08);
  border-left: 3px solid var(--ct-angle-stroke-2);
}

[data-theme="dark"] .ct-angle-row.ct-inscribed-2 {
  background: rgba(52, 211, 153, 0.1);
}

/* Angle diagram labels for the B/D pair */
.ct-angle-label-2 {
  fill: var(--ct-angle-stroke-2);
}


/* ── Tangent line ─────────────────────────────────────────────── */
:root { --ct-line-tangent-color: #0e7490; }
[data-theme="dark"] { --ct-line-tangent-color: #22d3ee; }

.ct-line-tangent {
  stroke: var(--ct-line-tangent-color);
  stroke-width: 1.8;
  stroke-linecap: round;
  fill: none;
}


/* ── Kite / triangle fill ─────────────────────────────────────── */
.ct-poly-fill {
  stroke: none;
  opacity: 0.08;
}
.ct-poly-fill.ct-hidden {
  opacity: 0;
  pointer-events: none;
}


/* ── Segment fill ─────────────────────────────────────────────── */
.ct-segment-fill {
  fill: var(--ct-segment-fill);
  stroke: none;
}


/* ── Right-angle square indicator ────────────────────────────── */
.ct-right-angle {
  fill: none;
  stroke: var(--ct-angle-stroke);
  stroke-width: 1.3;
}

.ct-snap-ticks line {
  stroke: var(--ct-centre);
  stroke-width: 1.2;
  opacity: 0.4;
}

.ct-point:focus {
  outline: none;
}
.ct-point:focus .ct-point-visible {
  stroke: var(--sm-indigo);
  stroke-width: 3;
}


/* ── Responsive ───────────────────────────────────────────────── */

/* Tablets and small laptops */
@media (max-width: 900px) {
  .ct-panel {
    width: 240px;
    padding: 12px 14px;
  }
  .ct-statement {
    font-size: 0.78rem;
  }
}

/* Phone: bottom sheet panel below SVG */
@media (max-width: 680px) {
  .ct-layout {
    flex-direction: column;
  }
  .ct-svg-area {
    flex: 1;
    min-height: 0;
    order: 1;
  }
  .ct-panel {
    width: 100%;
    max-height: none;
    padding: 0;
    gap: 0;
    border-right: none;
    border-top: 1px solid var(--sm-border);
    flex-shrink: 0;
    order: 2;
  }

  .ct-sheet-toggle {
    display: flex;
    min-height: 48px;
    padding: 10px 14px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    border: none;
    border-bottom: 1px solid var(--sm-border);
    background: var(--sm-surface);
    cursor: pointer;
    font-family: var(--sm-font);
    color: var(--sm-text);
  }

  /* Expanded: only “Hide panel” — theorem lives in the <select> below */
  .ct-panel:not(.ct-panel--collapsed) .ct-sheet-summary {
    display: none !important;
  }

  .ct-panel:not(.ct-panel--collapsed) .ct-sheet-label-expanded {
    display: block;
  }

  .ct-panel-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    max-height: min(52vh, 420px);
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    transition:
      max-height var(--sm-transition, 0.2s ease),
      opacity var(--sm-transition, 0.2s ease),
      padding var(--sm-transition, 0.2s ease);
  }

  .ct-panel.ct-classroom .ct-panel-body {
    max-height: min(58vh, 480px);
  }

  .ct-panel.ct-panel--collapsed .ct-panel-body {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    padding-top: 0;
    padding-bottom: 0;
    margin: 0;
    pointer-events: none;
  }

  .ct-panel.ct-panel--collapsed .ct-sheet-chevron {
    transform: rotate(-90deg);
  }

  @media (prefers-reduced-motion: reduce) {
    .ct-panel-body,
    .ct-sheet-chevron {
      transition: none;
    }
  }
}
