:root {
    --bg-0: #040608;
    --bg-1: #0c1116;
    --bg-2: #111823;
    --card: #0f151d;
    --accent: #53fc18;
    --accent-strong: #3bc014;
    --text: #e7f7e9;
    --text-dim: #9ab3a0;
    --border: #1c252f;
    --shadow: 0 25px 60px rgba(0, 0, 0, 0.45);
    --radius: 14px;
    --blur: 12px;
    --top-bar-height: 72px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Poppins', 'Noto Sans JP', sans-serif;
    background:
        radial-gradient(circle at 20% 20%, rgba(83, 252, 24, 0.07), transparent 35%),
        radial-gradient(circle at 80% 10%, rgba(59, 192, 20, 0.05), transparent 40%),
        linear-gradient(160deg, #05080c 0%, #0b1016 40%, #0a0f14 100%);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

.app {
    min-height: 100vh;
}

.top-bar {
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    padding: 12px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    background: rgba(5, 8, 12, 0.92);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(var(--blur));
    z-index: 100;
    box-shadow: var(--shadow);
    min-height: var(--top-bar-height);
}

.brand {
    display: flex;
    gap: 10px;
    align-items: center;
    min-width: 0;
    flex: 0 1 auto;
}

.brand i {
    color: var(--accent);
    background: rgba(83, 252, 24, 0.15);
    border: 1px solid rgba(83, 252, 24, 0.4);
    padding: 12px;
    border-radius: 12px;
    font-size: 20px;
}

.brand-copy {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.brand-kicker {
    font-size: 9px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-dim);
}

.brand h1 {
    font-size: 16px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: 0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-chip {
    padding: 7px 10px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-weight: 700;
    letter-spacing: 0.02em;
    font-size: 12px;
}

.status-chip.running {
    background: rgba(83, 252, 24, 0.12);
    border-color: rgba(83, 252, 24, 0.5);
    color: var(--accent);
    box-shadow: 0 10px 24px rgba(83, 252, 24, 0.15);
}

.status-chip.error {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.4);
    color: #fca5a5;
}

.status-chip.ended {
    background: rgba(255, 186, 107, 0.1);
    border-color: rgba(255, 186, 107, 0.45);
    color: #ffd89f;
    box-shadow: 0 10px 24px rgba(255, 186, 107, 0.12);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
    flex-shrink: 0;
}

.content {
    max-width: 1050px;
    margin: 0 auto;
    padding: 20px 16px 32px;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-areas:
        "control"
        "chart";
    gap: 20px;
}

.chart-card {
    grid-area: chart;
}

.input-card {
    grid-area: control;
}

.setup-panel {
    transform-origin: top;
    transition: transform 0.3s ease, opacity 0.3s ease, max-height 0.3s ease, padding 0.25s ease;
    max-height: 520px;
}

.setup-panel.closed {
    transform: translateY(-12px);
    opacity: 0;
    pointer-events: none;
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
}

.setup-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 24px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(var(--blur));
}

.collapsible {
    position: relative;
    overflow: hidden;
}

.collapsible-body {
    transition: max-height 0.25s ease, opacity 0.25s ease, padding-top 0.2s ease, padding-bottom 0.2s ease;
    max-height: 900px;
    opacity: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.collapsible.collapsed .collapsible-body {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden;
}

.collapse-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.collapse-toggle i {
    transition: transform 0.2s ease;
}

.collapse-toggle:hover {
    border-color: rgba(83, 252, 24, 0.35);
    transform: translateY(-1px);
}

.collapsible.collapsed .collapse-toggle i {
    transform: rotate(-90deg);
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.section-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.eyebrow {
    font-size: 11px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.section-head h2 {
    font-size: 20px;
    font-weight: 800;
    color: var(--text);
    white-space: nowrap;
}

.hint {
    color: var(--text-dim);
    font-size: 14px;
}

.form-grid {
    display: grid;
    gap: 14px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field-label {
    font-weight: 700;
    color: var(--text);
}

input[type="text"] {
    width: 100%;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
    color: var(--text);
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="text"]:focus {
    border-color: rgba(83, 252, 24, 0.5);
    box-shadow: 0 12px 24px rgba(83, 252, 24, 0.12);
}

.helper {
    font-size: 12px;
    color: var(--text-dim);
}

.button-row {
    display: flex;
    gap: 10px;
    margin-top: 6px;
    flex-wrap: wrap;
}

.button-row.vertical {
    flex-direction: column;
    align-items: stretch;
}

button {
    font-family: inherit;
}

.primary-button {
    flex: 1;
    background: linear-gradient(120deg, var(--accent) 0%, var(--accent-strong) 100%);
    color: #041104;
    border: none;
    border-radius: 12px;
    padding: 14px 16px;
    font-weight: 800;
    font-size: 15px;
    cursor: pointer;
    box-shadow: 0 16px 32px rgba(83, 252, 24, 0.2);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.primary-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 20px 40px rgba(83, 252, 24, 0.25);
}

.primary-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    filter: saturate(0.6);
}

.ghost-button {
    flex: 0 0 120px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.ghost-button:hover:not(:disabled) {
    transform: translateY(-2px);
    border-color: rgba(83, 252, 24, 0.4);
}

.ghost-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease;
    font-size: 12px;
}

.icon-button.ghost {
    background: rgba(255, 255, 255, 0.04);
}

.icon-button.compact {
    padding: 7px 10px;
    font-size: 12px;
}

.icon-button:hover {
    transform: translateY(-1px);
    border-color: rgba(83, 252, 24, 0.4);
}

.log-window {
    background: rgba(5, 8, 12, 0.8);
    border: 1px solid var(--border);
    border-radius: 12px;
    min-height: 120px;
    max-height: 200px;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
}

.log-entry {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.log-time {
    color: var(--text-dim);
    font-family: 'Poppins', sans-serif;
    font-weight: 700;
    letter-spacing: 0.04em;
    font-size: 10px;
}

.log-message {
    color: var(--text);
    line-height: 1.5;
    font-size: 10px;
}

.log-entry.decrease {
    border-color: rgba(255, 186, 107, 0.4);
    background: rgba(255, 186, 107, 0.12);
}

.log-entry.increase {
    border-color: rgba(83, 252, 24, 0.35);
    background: rgba(83, 252, 24, 0.12);
}

.log-window::-webkit-scrollbar {
    width: 10px;
}

.log-window::-webkit-scrollbar-track {
    background: transparent;
}

.log-window::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.log-window::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.18);
}

.chart-card .section-head {
    align-items: center;
    flex-wrap: nowrap;
    gap: 10px;
}

.chart-meta {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-start;
    min-width: 0;
    width: 100%;
}

.meta-block {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 130px;
    flex: 1 1 0;
}

.meta-label {
    color: var(--text-dim);
    font-size: 11px;
    letter-spacing: 0.02em;
}

.meta-value {
    font-size: 18px;
    font-weight: 800;
    color: var(--text);
}

.scale-controls {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    flex: 1 1 140px;
    margin-left: 20px;
}

.scale-buttons {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
}

.scale-btn {
    padding: 6px 9px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.scale-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(83, 252, 24, 0.35);
}

.scale-btn.active {
    background: rgba(83, 252, 24, 0.12);
    border-color: rgba(83, 252, 24, 0.4);
    color: var(--accent);
    box-shadow: 0 6px 14px rgba(83, 252, 24, 0.18);
}

.chart-wrap {
    width: 100%;
    background: rgba(5, 8, 12, 0.7);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 12px 10px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
    position: relative;
    height: clamp(240px, 50vh, 380px);
    min-height: 240px;
    overflow: hidden;
    resize: vertical;
}

.chart-scroll {
    overflow-x: auto;
    overflow-y: hidden;
    width: 100%;
    padding-bottom: 6px;
    height: 100%;
}

.chart-wrap canvas {
    width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
}

.chart-log {
    margin-top: 14px;
    background: rgba(5, 8, 12, 0.75);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.log-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.log-hint {
    color: var(--text-dim);
    font-size: 12px;
}

@media (min-width: 1100px) {
    .content {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-areas:
            "control control"
            "chart chart";
        align-items: start;
    }

    .chart-wrap {
        height: 520px;
    }
}

@media (max-width: 720px) {
    .content {
        padding: 20px 14px 32px;
        grid-template-columns: 1fr;
        grid-template-areas:
            "control"
            "chart";
    }

    .section-head {
        flex-direction: column;
        align-items: flex-start;
    }

    .section-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .top-bar {
        flex-direction: row;
        align-items: center;
        gap: 8px;
    }

    .card {
        padding: 18px;
    }

    .section-head h2 {
        font-size: 20px;
    }

    .chart-wrap {
        height: clamp(230px, 48vh, 340px);
    }

    .brand h1 {
        font-size: 15px;
    }

    .brand-kicker {
        font-size: 9px;
    }

    .status-chip {
        font-size: 12px;
        padding: 6px 9px;
    }

    .icon-button {
        font-size: 12px;
        padding: 6px 9px;
        gap: 6px;
    }

    .chart-card .section-head {
        align-items: center;
        flex-direction: row;
    }

    .chart-meta {
        gap: 6px;
    }

    .meta-block {
        min-width: 100px;
        padding: 7px 9px;
    }

    .meta-label {
        font-size: 10px;
    }

    .meta-value {
        font-size: 17px;
    }

    .button-row {
        flex-direction: column;
    }

    .ghost-button,
    .primary-button {
        width: 100%;
        flex: 1;
    }

    .status-chip {
        align-self: flex-start;
    }
}

@media (max-width: 480px) {
    .content {
        padding: 16px 12px 26px;
        gap: 14px;
    }

    .card {
        padding: 16px 14px;
    }

    .top-bar {
        padding: 10px 12px;
        gap: 6px;
    }

    .section-head h2 {
        font-size: 18px;
    }

    .chart-meta {
        width: 100%;
        flex-wrap: nowrap;
        gap: 6px;
        justify-content: space-between;
    }

    .meta-block {
        min-width: 120px;
        padding: 8px 9px;
    }

    .meta-label {
        font-size: 11px;
    }

    .meta-value {
        font-size: 16px;
    }

    .chart-wrap {
        padding: 10px 10px 8px;
        height: clamp(220px, 50vh, 320px);
    }

    .log-window {
        min-height: 140px;
        max-height: 200px;
        margin-top: 10px;
    }

    .button-row {
        gap: 8px;
    }

    .primary-button,
    .ghost-button {
        font-size: 14px;
        padding: 12px 12px;
    }
}
