/* ==========================================================================
   Ecosystem Energy Pyramid & 10% Transfer Law Simulator Style Sheet
   ========================================================================== */

:root {
    --color-producer: #2e7d32;
    --color-producer-bg: #e8f5e9;
    --color-producer-border: #81c784;
    --color-primary: #0277bd;
    --color-primary-bg: #e1f5fe;
    --color-primary-border: #4fc3f7;
    --color-secondary: #7b1fa2;
    --color-secondary-bg: #f3e5f5;
    --color-secondary-border: #ba68c8;
    --color-tertiary: #c62828;
    --color-tertiary-bg: #ffebee;
    --color-tertiary-border: #ef5350;
    --color-heat: #ff6d00;
    --color-heat-bg: #fff3e0;
    --color-bg: #f5f7fa;
    --color-card-bg: #ffffff;
    --color-text-main: #263238;
    --color-text-muted: #546e7a;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans TC", sans-serif;
    background-color: var(--color-bg);
    color: var(--color-text-main);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    background: linear-gradient(135deg, #1b5e20, #004d40);
    color: #ffffff;
    padding: 18px 24px;
    box-shadow: var(--shadow-md);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.header-content h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.header-content .subtitle {
    font-size: 0.9rem;
    color: #c8e6c9;
    margin-top: 4px;
}

.header-nav {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.tab-btn {
    padding: 8px 16px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
}

.tab-btn.active {
    background: #ffffff;
    color: #1b5e20;
    box-shadow: var(--shadow-sm);
}

.btn {
    padding: 8px 14px;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

.btn-sound {
    background: #ffb300;
    color: #212121;
}

.btn-sound:hover {
    background: #ffa000;
}

.btn-secondary {
    background: #e0e0e0;
    color: #333333;
}

.btn-secondary:hover {
    background: #d5d5d5;
}

.btn-outline {
    background: transparent;
    border: 1px solid #90a4ae;
    color: var(--color-text-main);
}

.btn-outline:hover {
    background: #eceff1;
}

/* Main Container */
.main-container {
    flex: 1;
    max-width: 1280px;
    width: 100%;
    margin: 0 auto;
    padding: 20px;
    position: relative;
}

/* Toast Notification */
.toast-box {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-md);
    color: #ffffff;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    animation: toastSlideIn 0.3s ease, toastFadeOut 0.3s ease 2.7s forwards;
    pointer-events: auto;
    max-width: 360px;
    font-size: 0.95rem;
}

.toast.toast-success {
    background: linear-gradient(135deg, #2e7d32, #43a047);
}

.toast.toast-error {
    background: linear-gradient(135deg, #c62828, #e53935);
}

.toast.toast-info {
    background: linear-gradient(135deg, #0277bd, #039be5);
}

@keyframes toastSlideIn {
    from { opacity: 0; transform: translateY(-12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toastFadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Tabs */
.tab-section {
    display: none;
}

.tab-section.active-section {
    display: block;
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Section 1: Placement Game */
.game-dashboard {
    background: var(--color-card-bg);
    border-radius: var(--radius-md);
    padding: 14px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.game-info {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 700;
    background: #e8f5e9;
    color: #2e7d32;
}

.status-tip {
    font-size: 0.88rem;
    color: var(--color-text-muted);
}

.game-actions {
    display: flex;
    gap: 8px;
}

.game-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
}

.section-title {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 12px;
    color: #37474f;
}

/* Pyramid Target Container */
.pyramid-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.pyramid-tier {
    border-radius: var(--radius-md);
    padding: 12px 16px;
    box-shadow: var(--shadow-sm);
    border: 2px dashed #b0bec5;
    transition: all 0.25s ease;
    display: flex;
    flex-direction: column;
    position: relative;
}

.tier-tertiary {
    width: 50%;
    background-color: var(--color-tertiary-bg);
    border-color: var(--color-tertiary-border);
}

.tier-secondary {
    width: 68%;
    background-color: var(--color-secondary-bg);
    border-color: var(--color-secondary-border);
}

.tier-primary {
    width: 84%;
    background-color: var(--color-primary-bg);
    border-color: var(--color-primary-border);
}

.tier-producers {
    width: 100%;
    background-color: var(--color-producer-bg);
    border-color: var(--color-producer-border);
}

.pyramid-tier.drag-over {
    border-style: solid;
    transform: scale(1.02);
    box-shadow: 0 0 16px rgba(46, 125, 50, 0.4);
}

.pyramid-tier.target-ready {
    border-style: solid;
    animation: targetGlow 1.2s infinite alternate;
}

@keyframes targetGlow {
    from { box-shadow: 0 0 4px rgba(255, 179, 0, 0.4); }
    to { box-shadow: 0 0 14px rgba(255, 179, 0, 0.9); }
}

.tier-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.92rem;
    margin-bottom: 8px;
    font-weight: 700;
    flex-wrap: wrap;
    gap: 4px;
}

.tier-tertiary .tier-label { color: var(--color-tertiary); }
.tier-secondary .tier-label { color: var(--color-secondary); }
.tier-primary .tier-label { color: var(--color-primary); }
.tier-producers .tier-label { color: var(--color-producer); }

.tier-ratio {
    font-size: 0.78rem;
    font-weight: normal;
    opacity: 0.85;
}

.tier-dropzone {
    min-height: 70px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    padding: 6px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.6);
}

.drop-hint {
    font-size: 0.8rem;
    color: #90a4ae;
    text-align: center;
    width: 100%;
    user-select: none;
    pointer-events: none;
}

/* Organisms Pool & Cards */
.pool-wrapper {
    background: var(--color-card-bg);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}

.pool-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.selected-tip {
    font-size: 0.85rem;
    color: #f57c00;
    font-weight: 600;
}

.cards-pool {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
    gap: 10px;
    max-height: 520px;
    overflow-y: auto;
    padding: 4px;
}

/* Card Component */
.organism-card {
    background: #ffffff;
    border: 1.5px solid #cfd8dc;
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    cursor: grab;
    user-select: none;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    display: flex;
    flex-direction: column;
    gap: 3px;
    position: relative;
}

.organism-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: #78909c;
}

.organism-card:active {
    cursor: grabbing;
}

.organism-card.selected {
    border: 2px solid #ff9800;
    box-shadow: 0 0 10px rgba(255, 152, 0, 0.6);
    transform: scale(1.04);
}

.organism-card.placed {
    cursor: default;
    box-shadow: none;
    border: 1px solid rgba(0, 0, 0, 0.12);
    padding: 4px 8px;
    font-size: 0.85rem;
    background: rgba(255, 255, 255, 0.9);
}

.card-top {
    display: flex;
    align-items: center;
    gap: 6px;
}

.card-icon {
    font-size: 1.3rem;
    line-height: 1;
}

.card-name {
    font-weight: 700;
    font-size: 0.92rem;
    color: #263238;
}

.card-role {
    font-size: 0.72rem;
    color: #78909c;
}

.card-desc {
    font-size: 0.74rem;
    color: #546e7a;
    line-height: 1.25;
    margin-top: 2px;
}

.organism-card.placed .card-desc {
    display: none;
}

/* Visual Feedback Animations */
.animate-correct {
    animation: correctPulse 0.6s ease forwards;
}

@keyframes correctPulse {
    0% { transform: scale(1); box-shadow: 0 0 0 rgba(76, 175, 80, 0.8); }
    50% { transform: scale(1.08); box-shadow: 0 0 20px rgba(76, 175, 80, 0.9); border-color: #4caf50; }
    100% { transform: scale(1); box-shadow: 0 0 4px rgba(76, 175, 80, 0.4); }
}

.animate-incorrect {
    animation: shakeError 0.5s ease;
}

@keyframes shakeError {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-8px); border-color: #f44336; }
    40%, 80% { transform: translateX(8px); border-color: #f44336; }
}

/* Section 2: 10% Calculator */
.calc-intro-card {
    background: #e8f5e9;
    border-left: 4px solid #2e7d32;
    padding: 16px 20px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
}

.calc-intro-card h2 {
    font-size: 1.15rem;
    color: #1b5e20;
    margin-bottom: 6px;
}

.calc-intro-card p {
    font-size: 0.92rem;
    color: #2e7d32;
}

.calc-grid {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 24px;
    align-items: start;
}

.calc-controls-card {
    background: var(--color-card-bg);
    border-radius: var(--radius-md);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.calc-controls-card h3 {
    font-size: 1.1rem;
    margin-bottom: 16px;
    color: #37474f;
}

.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    font-size: 0.88rem;
    font-weight: 600;
    color: #455a64;
    margin-bottom: 6px;
}

.input-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.input-row input[type="number"] {
    flex: 1;
    padding: 8px 12px;
    font-size: 1rem;
    border: 1px solid #b0bec5;
    border-radius: var(--radius-sm);
    font-weight: 600;
}

.input-row select {
    padding: 8px 12px;
    border: 1px solid #b0bec5;
    border-radius: var(--radius-sm);
    background: #f9fbe7;
    font-weight: 600;
}

input[type="range"] {
    width: 100%;
    margin-top: 4px;
    cursor: pointer;
}

.range-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    color: #78909c;
    margin-top: 2px;
}

.summary-stat-box {
    background: #eceff1;
    border-radius: var(--radius-sm);
    padding: 14px;
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.88rem;
}

.stat-row strong {
    color: #1b5e20;
}

/* Visualization Card */
.calc-visual-card {
    background: var(--color-card-bg);
    border-radius: var(--radius-md);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.calc-visual-card h3 {
    font-size: 1.1rem;
    margin-bottom: 16px;
    color: #37474f;
}

.pyramid-graphic-area {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 24px;
    padding: 16px;
    background: #fafafa;
    border-radius: var(--radius-md);
    border: 1px solid #eeeeee;
}

.graphic-row {
    display: grid;
    grid-template-columns: 100px 1fr 140px;
    align-items: center;
    gap: 12px;
}

.badge-tertiary { background: var(--color-tertiary-bg); color: var(--color-tertiary); }
.badge-secondary { background: var(--color-secondary-bg); color: var(--color-secondary); }
.badge-primary { background: var(--color-primary-bg); color: var(--color-primary); }
.badge-producers { background: var(--color-producer-bg); color: var(--color-producer); }

.bar-container {
    background: #e0e0e0;
    height: 38px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    display: flex;
    align-items: center;
}

.energy-bar {
    height: 100%;
    min-width: 48px;
    display: flex;
    align-items: center;
    padding: 0 10px;
    color: #ffffff;
    font-weight: 700;
    font-size: 0.88rem;
    transition: width 0.3s ease;
    box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.15);
}

.bar-tertiary { background: linear-gradient(90deg, #d32f2f, #ef5350); }
.bar-secondary { background: linear-gradient(90deg, #7b1fa2, #ab47bc); }
.bar-primary { background: linear-gradient(90deg, #0277bd, #29b6f6); }
.bar-producers { background: linear-gradient(90deg, #2e7d32, #66bb6a); }

.heat-flow-arrow {
    display: flex;
    flex-direction: column;
    font-size: 0.82rem;
    color: var(--color-heat);
    padding: 4px 8px;
    background: var(--color-heat-bg);
    border-radius: var(--radius-sm);
    border: 1px solid #ffe0b2;
}

.heat-flow-arrow .arrow-icon {
    font-size: 0.95rem;
}

.loss-label {
    font-size: 0.78rem;
    font-weight: 600;
}

/* Energy Table */
.energy-table-wrapper {
    overflow-x: auto;
    margin-bottom: 20px;
}

.energy-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.energy-table th, .energy-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #cfd8dc;
}

.energy-table th {
    background: #eceff1;
    color: #37474f;
    font-weight: 700;
}

.energy-table tr:hover td {
    background: #f5f5f5;
}

.insight-box {
    background: #fff8e1;
    border-left: 4px solid #ffb300;
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    color: #5d4037;
}

.insight-box strong {
    color: #e65100;
    display: block;
    margin-bottom: 4px;
}

.insight-box p {
    margin-top: 6px;
    line-height: 1.45;
}

/* Footer */
.app-footer {
    text-align: center;
    padding: 16px;
    color: #78909c;
    font-size: 0.82rem;
    border-top: 1px solid #e0e0e0;
    margin-top: auto;
    background: #ffffff;
}

/* Responsive Breakpoints */
@media (max-width: 900px) {
    .game-layout {
        grid-template-columns: 1fr;
    }
    .calc-grid {
        grid-template-columns: 1fr;
    }
    .graphic-row {
        grid-template-columns: 80px 1fr 110px;
        gap: 8px;
    }
    .pyramid-tier {
        width: 100% !important;
    }
}

@media (max-width: 500px) {
    .app-header {
        padding: 12px 16px;
    }
    .header-content h1 {
        font-size: 1.25rem;
    }
    .graphic-row {
        grid-template-columns: 1fr;
        gap: 6px;
    }
    .heat-arrow-col {
        margin-top: 2px;
    }
}