* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    max-width: 1180px;
    margin: 0 auto;
    padding: 20px;
    background: #e5e7eb;
    color: #333;
    line-height: 1.6;
}

/* 圖示（inline SVG） */
.ico {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.05em;
    height: 1.05em;
    flex: 0 0 auto;
    vertical-align: -0.15em;
    margin-inline-end: 0.55em;
}

.ico:last-child {
    margin-inline-end: 0;
}

.ico svg {
    display: block;
    width: 100%;
    height: 100%;
}

[hidden] {
    display: none !important;
}

/* Hero Section */
.hero {
    text-align: center;
    padding: 2.5rem 1.5rem;
    background: linear-gradient(135deg, #0ea5e9 0%, #14b8a6 100%);
    border-radius: 16px 16px 0 0;
    color: #fff;
    margin-bottom: 0;
}

.badge {
    display: inline-block;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    backdrop-filter: blur(4px);
}

.hero h1 {
    font-size: 1.75rem;
    margin: 1rem 0 0 0;
    line-height: 1.4;
}

.hero code {
    background: rgba(255, 255, 255, 0.22);
    padding: 2px 8px;
    border-radius: 6px;
    font-family: "SF Mono", Consolas, monospace;
    font-size: 1.45rem;
}

/* Intro Section */
.intro-section {
    background: #f3f4f6;
    border-radius: 0 0 16px 16px;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.intro-section > h2 {
    text-align: center;
    font-size: 0.85rem;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 0 0 1rem 0;
    font-weight: 500;
}

.steps {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-bottom: 16px;
}

.feature {
    background: #fff;
    border-radius: 8px;
    padding: 0.75rem 0.5rem;
    text-align: center;
}

.step-num {
    width: 28px;
    height: 28px;
    margin: 0 auto 0.35rem auto;
    border-radius: 50%;
    background: #0ea5e9;
    color: #fff;
    font-size: 0.85rem;
    font-weight: 700;
    line-height: 28px;
    text-align: center;
}

.feature-text {
    font-size: 0.8rem;
    color: #6b7280;
    font-weight: 500;
}

.info-box {
    background: #fff;
    border: 1px solid #e5e7eb;
    padding: 1.25rem;
    border-radius: 10px;
}

.info-box h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1rem;
    color: #1f2937;
}

.info-box p {
    margin: 0;
    color: #4b5563;
    font-size: 0.95rem;
}

.info-box code,
.hint code {
    background: #f3f4f6;
    padding: 1px 6px;
    border-radius: 5px;
    font-family: "SF Mono", Consolas, monospace;
    font-size: 0.85em;
    color: #0369a1;
}

.info-box hr {
    border: 0;
    border-top: 1px solid #f3f4f6;
    margin: 0.75rem 0;
}

.info-box .solution {
    color: #0ea5e9;
    font-weight: 600;
    font-size: 0.95rem;
}

/* ============================================
   卡片（取代選項 / 變數 / 手動取代規則 / 輸入輸出 各一張白底卡片）
   ============================================ */
.panel,
.io-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.panel {
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.panel-head h3 {
    margin: 0;
    font-size: 0.95rem;
    color: #374151;
    font-weight: 600;
}

.head-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.count {
    display: inline-block;
    background: #e0f2fe;
    color: #0369a1;
    border-radius: 10px;
    padding: 1px 8px;
    font-size: 12px;
    font-weight: 700;
}

.hint {
    font-size: 12px;
    color: #9ca3af;
    margin: 0.75rem 0 0 0;
}

/* Buttons */
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 14px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
    font-family: inherit;
}

button:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

button:disabled {
    opacity: 0.4;
    cursor: default;
}

button:disabled:hover {
    transform: none;
    box-shadow: none;
}

.btn-primary {
    background: #0ea5e9;
    color: #fff;
    font-weight: 700;
}

.btn-ghost {
    background: #e5e7eb;
    color: #4b5563;
}

.btn-ghost.danger {
    color: #b91c1c;
}

.btn-ghost.danger:hover {
    background: #ef4444;
    color: #fff;
}

.btn-icon {
    width: 30px;
    height: 30px;
    padding: 0;
    background: #e5e7eb;
    color: #6b7280;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1;
    flex: 0 0 auto;
}

.btn-icon:hover {
    background: #d1d5db;
}

.btn-icon.del:hover {
    background: #ef4444;
    color: #fff;
}

.btn-copied {
    background: #10b981 !important;
    color: #fff !important;
}

.btn-label {
    white-space: nowrap;
}

/* Form controls */
.opt-title {
    display: block;
    font-size: 12px;
    color: #6b7280;
    margin-bottom: 4px;
    font-weight: 600;
}

.opt-static {
    margin: 0;
    font-size: 13px;
    color: #4b5563;
    padding: 9px 0;
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
}

.opt-group {
    min-width: 0;
}

select,
input[type="text"],
textarea {
    width: 100%;
    font-family: inherit;
    font-size: 14px;
    color: #1f2937;
    border: 2px solid #d1d5db;
    border-radius: 8px;
    padding: 8px 10px;
    background: #fff;
    transition: all 0.2s;
}

select:focus,
input[type="text"]:focus,
textarea:focus {
    outline: none;
    border-color: #0ea5e9;
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

.check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #374151;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}

.check input[type="checkbox"] {
    width: auto;
    margin: 0;
    accent-color: #0ea5e9;
    cursor: pointer;
}

.nl-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    border-top: 1px dashed #e5e7eb;
    padding-top: 0.75rem;
    margin-top: 0.75rem;
}

.nl-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.nl-with {
    font-size: 12px;
    color: #6b7280;
    white-space: nowrap;
}

/* 預設以 CSS 隱藏，避免 HTML 的 hidden 屬性被覆寫或快取時露出來 */
.nl-with-group {
    display: none;
}

.nl-with-group.is-open {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
}

input.mini-input {
    width: 200px;
    max-width: 50vw;
    flex: 0 0 auto;
    padding: 5px 8px;
    font-size: 13px;
    border-width: 1px;
}

.nl-hint-inline {
    font-size: 11px;
    color: #9ca3af;
    white-space: nowrap;
}

/* 變數列：key 欄固定等寬，值輸入框全部左右對齊 */
.var-list {
    --var-key-width: 240px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* 量測「最長變數名稱」自然寬度時，暫時取消固定寬度 */
.var-list.measuring-keys .var-key {
    flex: 0 0 auto;
}

.var-item {
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 0.6rem;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 10px 12px;
}

.var-item.unfilled {
    border-color: #fcd34d;
    background: #fffbeb;
}

.var-key {
    flex: 0 0 var(--var-key-width);
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    max-width: 100%;
}

.var-key .tag {
    margin-inline-start: auto;
}

.var-key code {
    font-family: "SF Mono", Consolas, monospace;
    font-size: 12px;
    line-height: 1.5;
    background: #e0f2fe;
    color: #0369a1;
    padding: 5px 8px;
    border-radius: 5px;
    white-space: nowrap;
    max-width: 100%;
    overflow-x: auto;
}

input.var-name {
    width: 200px;
    max-width: 50vw;
    flex: 0 0 auto;
    padding: 5px 8px;
    font-family: "SF Mono", Consolas, monospace;
    font-size: 13px;
    border-width: 1px;
}

.var-name.invalid {
    border-color: #ef4444;
    background: #fef2f2;
}

.tag {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 700;
    line-height: 1.6;
}

.tag-auto {
    background: #dcfce7;
    color: #15803d;
}

.tag-manual {
    background: #ede9fe;
    color: #6d28d9;
}

.var-value {
    flex: 1 1 320px;
    min-width: 120px;
    min-height: 40px;
    max-height: 260px;
    overflow: auto;
    resize: vertical;
    padding: 8px 10px;
    font-family: "SF Mono", Consolas, monospace;
    font-size: 13px;
    border-width: 1px;
    white-space: pre-wrap;
    word-break: break-word;
}

.var-actions {
    display: flex;
    gap: 4px;
    padding-top: 1px;
}

/* 手動取代規則 */
.rule-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.rule-item {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 8px 10px;
}

.rule-item.invalid {
    border-color: #ef4444;
    background: #fef2f2;
}

.rule-item input[type="text"] {
    flex: 1 1 140px;
    min-width: 110px;
    padding: 6px 8px;
    font-family: "SF Mono", Consolas, monospace;
    font-size: 13px;
    border-width: 1px;
}

.rule-arrow {
    color: #9ca3af;
    font-size: 13px;
    flex: 0 0 auto;
}

.empty-msg {
    color: #9ca3af;
    font-size: 13px;
    margin: 0;
    padding: 6px 0;
}

/* 輸入 / 輸出區 */
.io-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.io-card {
    display: flex;
    flex-direction: column;
    padding: 1.25rem;
}

.io-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
}

.io-head h3 {
    margin: 0;
    font-size: 0.95rem;
    color: #374151;
    font-weight: 600;
}

.io-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.io-card textarea {
    height: 340px;
    padding: 12px;
    font-family: "SF Mono", Consolas, monospace;
    font-size: 13px;
    line-height: 1.6;
    resize: vertical;
    background: #fff;
}

.io-foot {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 12px;
    color: #9ca3af;
    margin-top: 6px;
}

.warn {
    background: #fffbeb;
    border: 1px solid #fcd34d;
    color: #92400e;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 13px;
    margin-top: 0;
    margin-bottom: 1rem;
}

.warn code {
    font-family: "SF Mono", Consolas, monospace;
    background: #fef3c7;
    padding: 1px 6px;
    border-radius: 5px;
}

footer {
    margin-top: 1.5rem;
    text-align: center;
    color: #9ca3af;
    font-size: 0.85rem;
}

footer a {
    color: #0ea5e9;
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

.app-version {
    font-size: 11px;
    color: #b6bcc6;
    font-family: "SF Mono", Consolas, monospace;
}

/* Responsive */
@media (max-width: 860px) {
    .io-grid {
        grid-template-columns: 1fr;
    }

    .options-grid,
    .steps {
        grid-template-columns: 1fr;
    }

    .hero h1 {
        font-size: 1.4rem;
    }

    .hero code {
        font-size: 1.15rem;
    }

    .var-key {
        flex: 1 1 100%;
        max-width: 100%;
    }

    .var-value {
        flex: 1 1 100%;
    }
}
