:root {
    --ink: #1b2430;
    --ink-soft: #26314100;
    --panel: #212b39;
    --panel-border: #35435830;
    --paper: #faf7f0;
    --accent: #5b8ec2;
    --accent-strong: #7fa8d6;
    --accent-soft: rgba(91, 142, 194, 0.18);
    --muted: #97a2b5;
    --danger: #c9705f;
    --danger-strong: #e38270;

    --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    font-family: var(--sans);
    background: var(--paper);
}

#app {
    position: fixed;
    inset: 0;
}

#tree-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
}

#tree-canvas:active {
    cursor: grabbing;
}

#hidden-text-input {
    position: fixed;
    top: -100px;
    left: -100px;
    width: 1px;
    height: 1px;
    opacity: 0;
    display: none;
    border: none;
    outline: none;
    pointer-events: none;
}

#toolbar {
    position: absolute;
    top: 18px;
    left: 18px;
    display: flex;
    align-items: center;
    gap: 2px;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 6px;
    box-shadow: 0 10px 30px rgba(10, 14, 20, 0.35);
    z-index: 20;
}

#toolkit {
    position: absolute;
    top: 18px;
    right: 18px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 6px;
    box-shadow: 0 10px 30px rgba(10, 14, 20, 0.35);
    z-index: 20;
}

#toolkit .title {
    align-self: center;
    font-family: var(--mono);
    font-size: 14px;
    letter-spacing: 0.02em;
    color: var(--paper);
    white-space: nowrap;
}

#toolkit .glyph {
    width: 22px;
    height: 22px;
}

.toolkit-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--mono);
    font-size: 12.5px;
    letter-spacing: 0.01em;
    color: var(--muted);
    background: var(--panel);
    border: none;
    border-radius: 8px;
    padding: 9px 8px;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
    white-space: nowrap;
}

.toolkit-btn:hover {
    background: var(--accent-soft);
    color: var(--paper);
}

.toolkit-btn:active {
    background: rgba(91, 142, 194, 0.3);
}

#wordmark {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px 0 8px;
    margin-right: 4px;
    border-right: 1px solid var(--panel-border);
}

#wordmark .glyph {
    width: 22px;
    height: 22px;
    flex: none;
    object-fit: contain;
    border-radius: 5px;
    display: block;
}

#wordmark .label {
    font-family: var(--mono);
    font-size: 14px;
    letter-spacing: 0.02em;
    color: var(--paper);
    white-space: nowrap;
}

#wordmark .label .bracket {
    color: var(--accent-strong);
}

.toolbar-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--mono);
    font-size: 12.5px;
    letter-spacing: 0.01em;
    color: var(--muted);
    background: transparent;
    border: none;
    border-radius: 8px;
    padding: 9px 12px;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
    white-space: nowrap;
}

.toolbar-btn:hover {
    background: var(--accent-soft);
    color: var(--paper);
}

.toolbar-btn:active {
    background: rgba(91, 142, 194, 0.3);
}

.toolbar-btn.primary {
    color: var(--accent-strong);
}

.settings-btn {
    display: center;
    align-items: center;
    gap: 6px;
    font-family: var(--sans);
    font-size: 12.5px;
    letter-spacing: 0.01em;
    color: var(--muted);
    background: var(--accent-soft);
    border: none;
    border-radius: 8px;
    padding: 9px 12px;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
    white-space: nowrap;
}

.settings-btn:hover {
    background: var(--accent-strong);
    color: var(--paper);
}

.settings-btn:active {
    background: rgba(91, 142, 194, 0.3);
}

.panel {
    position: absolute;
    top: 18px;
    left: 18px;
    width: 300px;
    max-height: calc(100vh - 36px);
    overflow-y: auto;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    box-shadow: 0 20px 50px rgba(10, 14, 20, 0.45);
    color: var(--paper);
    z-index: 30;
    transform: translateX(-120%);
    opacity: 0;
    transition: transform 0.18s ease, opacity 0.18s ease;
    pointer-events: none;
}

.panel.visible {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}

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

.panel-header h2 {
    margin: 0;
    font-family: var(--mono);
    font-size: 13px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.panel-close {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
}

.panel-close:hover {
    color: var(--paper);
    background: rgba(255, 255, 255, 0.06);
}

.panel-body {
    padding: 14px 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.field label {
    display: block;
    font-size: 12.5px;
    color: var(--muted);
    margin-bottom: 8px;
}

.field .value {
    color: var(--accent-strong);
    font-family: var(--mono);
}

.field input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

.field-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.toggle-row label {
    font-size: 13px;
    color: var(--paper);
    margin: 0;
}

.switch {
    position: relative;
    display: inline-block;
    width: 38px;
    height: 22px;
    flex: none;
}

.switch input { opacity: 0; width: 0; height: 0; }

.switch .slider {
    position: absolute;
    inset: 0;
    background: #3a4658;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.switch .slider::before {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    top: 3px;
    background: var(--paper);
    border-radius: 50%;
    transition: transform 0.15s ease;
}

.switch input:checked + .slider {
    background: var(--accent);
}

.switch input:checked + .slider::before {
    transform: translateX(16px);
}

.section-title {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin: 4px 0 -6px;
}

.color-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.color-row label {
    flex: 1;
    font-size: 13px;
    color: var(--paper);
}

.color-row input[type="color"] {
    width: 30px;
    height: 26px;
    padding: 0;
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    background: none;
    cursor: pointer;
}

.color-row input[type="range"] {
    width: 70px;
    accent-color: var(--accent);
}

#subscript-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -46%);
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    box-shadow: 0 20px 50px rgba(10, 14, 20, 0.5);
    padding: 18px;
    width: 220px;
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.18s;
}

#subscript-modal.visible {
    pointer-events: auto;
    opacity: 1;
}

#subscript-modal h3 {
    margin: 0;
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
}

#subscript-input {
    width: 100%;
    background: #151c26;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    color: var(--paper);
    font-size: 15px;
    padding: 9px 10px;
    font-family: var(--sans);
}

#subscript-input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

#subscript-done {
    align-self: flex-end;
    background: var(--accent);
    color: #0d141d;
    border: none;
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.04em;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
}

#subscript-done:hover {
    background: var(--accent-strong);
}

#title-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -46%);
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    box-shadow: 0 20px 50px rgba(10, 14, 20, 0.5);
    padding: 18px;
    width: 220px;
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.18s;
}

#title-modal.visible {
    pointer-events: auto;
    opacity: 1;
}

#title-modal h3 {
    margin: 0;
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
}

#title-input {
    width: 100%;
    background: #151c26;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    color: var(--paper);
    font-size: 15px;
    padding: 9px 10px;
    font-family: var(--sans);
}

#title-input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

#title-done {
    align-self: flex-end;
    background: var(--accent);
    color: #0d141d;
    border: none;
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.04em;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
}

#title-done:hover {
    background: var(--accent-strong);
}

#confirmation-modal {
    display: flex;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -46%);
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    box-shadow: 0 20px 50px rgba(10, 14, 20, 0.5);
    padding: 18px;
    width: 220px;
    z-index: 40;
    flex-direction: column;
    gap: 12px;
    opacity: 0;
    transition: opacity 0.18s;
    pointer-events: none;
}

#confirmation-modal.visible {
    opacity: 1;
    pointer-events: auto;
}

#confirmation-title {
    margin: 0;
    font-family: var(--sans);
    font-size: 12px;
    letter-spacing: 0.05em;
    color: var(--muted);
}

#confirmation-ok {
    align-self: flex;
    background: var(--accent);
    color: #0d141d;
    border: none;
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.04em;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
}

#confirmation-ok:hover {
    background: var(--accent-strong);
}

#confirmation-cancel {
    align-self: flex;
    background: var(--danger);
    color: #0d141d;
    border: none;
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.04em;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
}

#confirmation-cancel:hover {
    background: var(--danger-strong);
}

#hint-bar {
    position: absolute;
    bottom: 16px;
    right: 16px;
    max-width: 340px;
    background: rgba(27, 36, 48, 0.92);
    color: var(--muted);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 12px;
    line-height: 1.55;
    z-index: 20;
    box-shadow: 0 10px 30px rgba(10, 14, 20, 0.3);
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
    transition: transform 0.25s ease, opacity 0.25s ease;
}


#hint-bar .hint-header {
    border-bottom: 1px solid var(--panel-border);
}

#hint-bar.hidden {
    transform: translateX(120%);
    opacity: 0;
    pointer-events: none;
}

#hint-bar b { color: var(--paper); }

#hint-bar .hint-close {
    float: right;
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 18px;
    margin-left: 8px;
    padding: 4px 6px;
    border-radius: 6px;
}

#hint-bar .hint-close:hover {
    color: var(--paper);
    background: rgba(255, 255, 255, 0.06);
}

#hint-bar h2 {
    margin: 0;
    font-family: var(--mono);
    font-size: 13px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

@media (max-width: 640px) {
    #wordmark .label { display: none; }
    .toolbar-btn span.txt { display: none; }
    #hint-bar { left: 16px; max-width: none; }
    .panel { width: calc(100vw - 36px); }
}

a.about:link {
  color: cyan;
}

a.about:visited {
  color: cyan;
}

a.about:hover {
  color: blue;
  text-decoration: underline;
}

a.about:active {
  color: orange;
}
