/* =============================================
   ACM Playground - ACM 模拟 IDE 样式
   复用 style.css 的 CSS 变量
   ============================================= */

/* 当前页面导航高亮 */
.nav-link-active {
    color: var(--primary) !important;
}

.nav-link-active::after {
    width: 100% !important;
}

/* ---------- 主布局 ---------- */
.acm-main {
    margin-top: 60px;
    height: calc(100vh - 60px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ---------- 工具栏 ---------- */
.acm-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    gap: var(--spacing-md);
    flex-shrink: 0;
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: var(--border-color);
    margin: 0 var(--spacing-xs);
}

.template-select {
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: var(--font-sans);
    min-width: 180px;
    cursor: pointer;
}

.template-select:focus {
    outline: none;
    border-color: var(--primary);
}

.language-select {
    min-width: 118px;
}

/* 运行时状态 */
.runtime-status {
    font-size: 0.8rem;
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

.runtime-status.loading {
    color: var(--medium);
    background: rgba(255, 192, 30, 0.12);
}

.runtime-status.ready {
    color: var(--easy);
    background: rgba(0, 184, 163, 0.12);
}

.runtime-status.error {
    color: var(--hard);
    background: rgba(255, 55, 95, 0.12);
}

/* 按钮 */
.btn-run {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-md);
    background: linear-gradient(135deg, var(--easy), #00d4aa);
    color: #000;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-run:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(0, 184, 163, 0.4);
}

.btn-run:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-debug {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-md);
    background: linear-gradient(135deg, #ffa116, #ff6b00);
    color: #000;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-debug:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(255, 161, 22, 0.4);
}

.btn-debug:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-reset {
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-reset:hover {
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.btn-save-code {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-tertiary);
    color: var(--primary-light);
    border: 1px solid var(--primary);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition-fast);
}

.btn-save-code:hover {
    color: var(--text-primary);
    background: var(--bg-card-hover);
    box-shadow: 0 3px 12px rgba(124, 92, 255, 0.22);
}

/* ---------- 两栏布局 ---------- */
.acm-layout {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.acm-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.acm-panel-editor {
    width: 55%;
    min-width: 400px;
    border-right: 1px solid var(--border-color);
}

.acm-panel-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.acm-panel-input {
    flex: 1;
    min-height: 80px;
}

.acm-panel-output {
    flex: 1;
    min-height: 80px;
    border-top: 1px solid var(--border-color);
}

.acm-panel-expected {
    flex: 0.7;
    min-height: 60px;
    border-top: 1px solid var(--border-color);
}

.acm-panel-debug {
    flex: 1.5;
    min-height: 100px;
    border-top: 2px solid var(--medium);
}

/* 面板头 */
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 36px;
    box-sizing: border-box;
    padding: var(--spacing-xs) var(--spacing-md);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.panel-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.panel-hint {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.panel-header-tools,
.workspace-actions {
    display: flex;
    align-items: center;
}

.panel-header-tools {
    gap: var(--spacing-sm);
    min-width: 0;
}

.workspace-actions {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
    flex-shrink: 0;
}

.workspace-action-btn {
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 0 7px;
    background: var(--bg-secondary);
    color: var(--text-muted);
    border: none;
    font-family: var(--font-sans);
    font-size: 0.72rem;
    cursor: pointer;
    white-space: nowrap;
    transition: color var(--transition-fast), background var(--transition-fast);
}

.workspace-action-btn + .workspace-action-btn {
    border-left: 1px solid var(--border-color);
}

.workspace-action-btn:hover {
    color: var(--text-primary);
    background: var(--bg-card-hover);
}

.workspace-action-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
}

.workspace-action-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn-save-code:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.panel-action-btn {
    font-size: 0.72rem;
    color: var(--text-muted);
    background: none;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 2px 8px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.panel-action-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-hover);
}

/* 面板内容 */
.panel-body {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-primary);
}

/* ---------- CodeMirror 覆盖 ---------- */
.editor-body {
    padding: 0 !important;
}

.editor-body .CodeMirror {
    height: 100%;
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.6;
}

/* 断点 gutter */
.CodeMirror-linenumber {
    cursor: pointer;
}

.acm-breakpoint {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--hard);
    display: inline-block;
    margin: 3px 0 0 2px;
    box-shadow: 0 0 6px rgba(255, 55, 95, 0.6);
}

/* 调试当前行高亮 */
.debug-current-line {
    background: rgba(255, 192, 30, 0.15) !important;
}

/* CodeMirror 自动补全 */
.CodeMirror-hints {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    font-family: var(--font-mono);
    font-size: 13px;
    z-index: 1100;
}

.CodeMirror-hint {
    color: var(--text-primary) !important;
    padding: 4px 8px !important;
    border-radius: 3px;
}

.CodeMirror-hint-active {
    background: var(--primary) !important;
    color: white !important;
}

/* ---------- 输入输出区域 ---------- */
.io-body {
    padding: 0 !important;
}

.io-textarea {
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: none;
    outline: none;
    resize: none;
    padding: var(--spacing-sm) var(--spacing-md);
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    box-sizing: border-box;
}

.io-textarea::placeholder {
    color: var(--text-muted);
}

.io-output {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: var(--spacing-sm) var(--spacing-md);
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-all;
    overflow-y: auto;
    box-sizing: border-box;
}

.io-output.has-error {
    color: var(--hard);
}

.io-output.placeholder-text {
    color: var(--text-muted);
}

/* 运行状态 */
.run-status {
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-family: var(--font-mono);
}

.run-status.success {
    color: var(--easy);
    background: rgba(0, 184, 163, 0.12);
}

.run-status.error {
    color: var(--hard);
    background: rgba(255, 55, 95, 0.12);
}

.run-status.running {
    color: var(--medium);
    background: rgba(255, 192, 30, 0.12);
}

/* 输出对比结果 */
.diff-result {
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-weight: 600;
}

.diff-result.match {
    color: var(--easy);
    background: rgba(0, 184, 163, 0.12);
}

.diff-result.mismatch {
    color: var(--hard);
    background: rgba(255, 55, 95, 0.12);
}

/* ---------- 调试面板 ---------- */
.debug-controls {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-xs) var(--spacing-md);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.debug-step-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.debug-step-btn:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--primary);
}

.debug-step-info {
    font-size: 0.8rem;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    min-width: 80px;
    text-align: center;
}

.debug-controls-sep {
    width: 1px;
    height: 20px;
    background: var(--border-color);
}

.debug-body {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-primary);
}

.debug-vars-header {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: var(--spacing-xs) var(--spacing-md);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.debug-vars {
    padding: var(--spacing-sm) var(--spacing-md);
}

.debug-placeholder {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
    padding: var(--spacing-lg);
}

.debug-var-row {
    display: flex;
    align-items: baseline;
    gap: var(--spacing-sm);
    padding: 3px 0;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    border-bottom: 1px solid var(--border-color);
}

.debug-var-row:last-child {
    border-bottom: none;
}

.debug-var-name {
    color: var(--primary-light);
    font-weight: 600;
    min-width: 60px;
    flex-shrink: 0;
}

.debug-var-eq {
    color: var(--text-muted);
}

.debug-var-value {
    color: var(--text-primary);
    word-break: break-all;
}

.debug-var-changed {
    background: rgba(255, 192, 30, 0.15);
    border-radius: 3px;
    padding: 0 4px;
}

/* ---------- 底部状态栏 ---------- */
.acm-statusbar {
    display: flex;
    align-items: center;
    padding: 3px var(--spacing-md);
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
    font-size: 0.72rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    flex-shrink: 0;
    gap: var(--spacing-sm);
}

.statusbar-sep {
    color: var(--border-color);
}

.statusbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.statusbar-tip {
    color: var(--text-muted);
}

.runtime-credit {
    text-decoration: none;
    transition: color 0.15s ease;
}

.runtime-credit:hover {
    color: var(--text-primary);
}

/* ---------- 文件保存与练习包 ---------- */
.file-toast {
    position: fixed;
    z-index: 1300;
    top: 76px;
    right: var(--spacing-md);
    max-width: min(420px, calc(100vw - 32px));
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--easy);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: var(--shadow-md);
    font-size: 0.82rem;
    line-height: 1.45;
    opacity: 0;
    transform: translateY(-8px);
    pointer-events: none;
    transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.file-toast.error {
    border-left-color: var(--hard);
}

.file-toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.file-dialog {
    width: min(420px, calc(100vw - 32px));
    margin: auto;
    padding: 0;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
}

.file-dialog::backdrop {
    background: rgba(0, 0, 0, 0.66);
}

.file-dialog-form {
    margin: 0;
}

.file-dialog-header,
.file-dialog-footer {
    display: flex;
    align-items: center;
}

.file-dialog-header {
    height: 48px;
    justify-content: space-between;
    padding: 0 var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
}

.file-dialog-header h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0;
}

.dialog-close-btn {
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.dialog-close-btn:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.file-dialog-body {
    padding: var(--spacing-lg) var(--spacing-md) var(--spacing-md);
}

.file-dialog-body label {
    display: block;
    margin-bottom: var(--spacing-xs);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
}

.filename-field {
    height: 40px;
    display: flex;
    align-items: stretch;
    overflow: hidden;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.filename-field:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(124, 92, 255, 0.16);
}

.filename-field.has-error {
    border-color: var(--hard);
}

.filename-field input {
    min-width: 0;
    flex: 1;
    padding: 0 var(--spacing-sm);
    color: var(--text-primary);
    background: transparent;
    border: none;
    outline: none;
    font-family: var(--font-mono);
    font-size: 0.9rem;
}

.filename-extension {
    display: inline-flex;
    align-items: center;
    padding: 0 var(--spacing-sm);
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border-left: 1px solid var(--border-color);
    font-family: var(--font-mono);
    font-size: 0.86rem;
}

.filename-error {
    min-height: 18px;
    margin: 5px 0 0;
    color: var(--hard);
    font-size: 0.75rem;
    line-height: 18px;
}

.file-dialog-footer {
    justify-content: flex-end;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
}

.dialog-btn {
    min-width: 72px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 0 var(--spacing-md);
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
}

.dialog-btn-cancel {
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
}

.dialog-btn-confirm {
    color: #000;
    background: var(--easy);
    border: 1px solid var(--easy);
}

.dialog-btn:hover {
    filter: brightness(1.08);
}

.dialog-close-btn:focus-visible,
.dialog-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ---------- 响应式 ---------- */
@media (max-width: 1100px) and (min-width: 769px) {
    .acm-toolbar {
        flex-wrap: wrap;
    }

    .toolbar-left {
        width: 100%;
    }

    .toolbar-right {
        margin-left: auto;
    }
}

@media (max-width: 768px) {
    .acm-layout {
        flex-direction: column;
    }

    .acm-panel-editor {
        width: 100%;
        min-width: unset;
        height: 45%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .acm-panel-right {
        height: 55%;
    }

    .acm-toolbar {
        flex-wrap: wrap;
    }

    .toolbar-left {
        width: 100%;
        display: grid;
        grid-template-columns: minmax(105px, 0.75fr) minmax(145px, 1.25fr);
        gap: var(--spacing-sm);
    }

    .template-select {
        width: 100%;
        min-width: unset;
    }

    .toolbar-divider {
        display: none;
    }

    .runtime-status {
        justify-self: start;
        align-self: center;
    }

    .toolbar-right {
        width: 100%;
        justify-content: flex-end;
        flex-wrap: wrap;
    }

    .toolbar-right .btn-run,
    .toolbar-right .btn-debug,
    .toolbar-right .btn-reset,
    .toolbar-right .btn-save-code {
        padding-left: var(--spacing-sm);
        padding-right: var(--spacing-sm);
    }

    .run-shortcut {
        display: none;
    }

    .acm-panel-editor .panel-hint {
        display: none;
    }

    .acm-statusbar > .statusbar-sep,
    #status-time,
    .statusbar-right > .statusbar-tip:not(.runtime-credit),
    .statusbar-right > .statusbar-sep {
        display: none;
    }

    #status-info {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .runtime-credit {
        flex-shrink: 0;
        white-space: nowrap;
    }
}

@media (max-width: 360px) {
    .workspace-action-btn {
        width: 30px;
        padding: 0;
    }

    .workspace-action-label {
        display: none;
    }
}
