/* ==========================================================================
   OmNomNom — 台灣濕地食物鏈桌遊 樣式表
   ========================================================================== */

:root {
    --c-primary: #00796b;
    --c-primary-dark: #004d40;
    --c-bg: #eef3f1;
    --c-card: #ffffff;
    --c-text: #263238;
    --c-muted: #607d8b;
    --t1: #2e7d32; --t1-bg: #e8f5e9; --t1-bd: #a5d6a7;
    --t2: #7b1fa2; --t2-bg: #f3e5f5; --t2-bd: #ce93d8;
    --t3: #c62828; --t3-bg: #ffebee; --t3-bd: #ef9a9a;
    --radius: 12px;
    --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.2);
}

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

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

img, svg, canvas { max-width: 100%; }

[hidden] { display: none !important; }

/* ---------- Header ---------- */
.game-header {
    background: linear-gradient(135deg, #004d40, #00695c, #00796b);
    color: #fff;
    padding: 14px 24px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    box-shadow: var(--shadow-md);
}
.header-main h1 { font-size: 1.45rem; }
.header-main .subtitle { font-size: 0.85rem; color: #b2dfdb; }
.header-controls { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Buttons ---------- */
.btn {
    border: none;
    border-radius: 8px;
    padding: 9px 16px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.12s, box-shadow 0.12s, background 0.12s, opacity 0.12s;
    font-family: inherit;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--c-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--c-primary-dark); }
.btn-info { background: #ffffff; color: var(--c-primary-dark); }
.btn-sound, .btn-outline { background: rgba(255, 255, 255, 0.15); color: #fff; border: 1px solid rgba(255, 255, 255, 0.5); }
.btn-dice { background: #ff8f00; color: #fff; }
.btn-dice:hover:not(:disabled) { background: #ef6c00; }
.btn-lg { padding: 12px 30px; font-size: 1.1rem; }

/* ---------- Layout ---------- */
.game-container {
    flex: 1;
    width: 100%;
    max-width: 1320px;
    margin: 0 auto;
    padding: 18px;
}

.setup-panel {
    max-width: 560px;
    margin: 40px auto;
    background: var(--c-card);
    border-radius: 18px;
    padding: 32px;
    text-align: center;
    box-shadow: var(--shadow-md);
}
.setup-panel h2 { color: var(--c-primary-dark); margin-bottom: 8px; }
.setup-panel p { color: var(--c-muted); margin-bottom: 20px; }
.setup-row { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }
.opponent-picker { display: flex; gap: 6px; }
.btn-choice {
    border: 2px solid var(--c-primary);
    background: #fff;
    color: var(--c-primary);
    border-radius: 8px;
    padding: 6px 16px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}
.btn-choice.active { background: var(--c-primary); color: #fff; }

/* ---------- Scoreboard ---------- */
.scoreboard-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}
.player-scores { display: flex; flex-wrap: wrap; gap: 12px; flex: 1; }
.score-card {
    background: var(--c-card);
    border-radius: var(--radius);
    padding: 10px 16px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    min-width: 150px;
}
.player-card { border-left: 6px solid var(--pc); flex: 1; }
.score-label { font-size: 0.8rem; color: var(--c-muted); font-weight: 600; }
.score-value { font-size: 1.15rem; }
.score-value strong { font-size: 1.5rem; color: var(--c-primary-dark); }
.score-sub { font-size: 0.75rem; color: var(--c-muted); }
.round-card .score-value { font-weight: 700; color: var(--c-primary-dark); }

.board-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 18px;
    align-items: start;
}
.board-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

/* ---------- Board ---------- */
.board {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px 10px;
    background: var(--c-card);
    padding: 12px;
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
}
.chain-header {
    text-align: center;
    font-weight: 700;
    color: var(--c-primary-dark);
    background: #e0f2f1;
    border-radius: 8px;
    padding: 6px 4px;
    font-size: 0.92rem;
}
.cell {
    position: relative;
    border-radius: 10px;
    border: 2px solid;
    padding: 8px;
    min-height: 118px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: box-shadow 0.25s, transform 0.25s;
}
.cell.tier-1 { background: var(--t1-bg); border-color: var(--t1-bd); }
.cell.tier-2 { background: var(--t2-bg); border-color: var(--t2-bd); }
.cell.tier-3 { background: var(--t3-bg); border-color: var(--t3-bd); }
.cell-head { display: flex; align-items: center; gap: 8px; }
.cell-title { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.cell-title strong { font-size: 1.05rem; }
.cell-title small { font-size: 0.72rem; color: var(--c-muted); }
.cell.tier-1 .cell-title strong { color: var(--t1); }
.cell.tier-2 .cell-title strong { color: var(--t2); }
.cell.tier-3 .cell-title strong { color: var(--t3); }

.sp-icon { display: inline-flex; width: 34px; height: 34px; align-items: center; justify-content: center; font-size: 28px; flex-shrink: 0; }
.sp-icon svg { width: 100%; height: 100%; }
.sp-icon.big { width: 44px; height: 44px; font-size: 36px; }

.cell-dice, .cell-cards { display: flex; flex-wrap: wrap; gap: 4px; min-height: 0; }
.die {
    width: 32px; height: 32px;
    display: inline-flex; align-items: center; justify-content: center;
    background: #fff;
    border: 2px solid #90a4ae;
    border-radius: 7px;
    font-size: 19px;
    box-shadow: 0 2px 0 #90a4ae;
    animation: pop 0.25s ease-out;
}
.die svg { width: 24px; height: 24px; }
.mini-card {
    background: var(--pc);
    color: #fff;
    font-size: 0.78rem;
    font-weight: 700;
    border-radius: 6px;
    padding: 3px 9px;
    box-shadow: var(--shadow-sm);
    animation: flipIn 0.4s ease-out;
}
.mini-card.eaten { background: #9e9e9e; text-decoration: line-through; opacity: 0.75; }
.mini-card.eaten::after { content: ' 🍽️被吃'; text-decoration: none; }

.cell-badge {
    position: absolute;
    top: 6px; right: 6px;
    background: #ffb300;
    color: #fff;
    font-weight: 800;
    font-size: 0.8rem;
    border-radius: 999px;
    padding: 2px 10px;
    opacity: 0;
    transform: scale(0.6);
    transition: opacity 0.2s, transform 0.2s;
}
.cell-badge.show { opacity: 1; transform: scale(1); }
.cell-badge.miss { background: #90a4ae; }
.cell.flash-eat { box-shadow: 0 0 0 4px #ffca28, var(--shadow-md); transform: scale(1.02); }
.cell.flash-eaten { box-shadow: 0 0 0 4px #e53935; }

.flow-arrow {
    text-align: center;
    color: #26a69a;
    font-weight: 800;
    font-size: 0.95rem;
    line-height: 1;
}
.flow-arrow small { font-size: 0.68rem; font-weight: 600; color: var(--c-muted); }

/* ---------- Control bar ---------- */
.control-bar {
    background: var(--c-card);
    border-radius: 14px;
    padding: 12px 16px;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}
.dice-box { flex-shrink: 0; }
.dice-visual {
    width: 54px; height: 54px;
    border-radius: 12px;
    background: #fff8e1;
    border: 2px solid #ffb300;
    display: flex; align-items: center; justify-content: center;
    font-size: 32px;
}
.dice-visual.dice-rolling { animation: shake 0.15s infinite; }
.dice-result-text { flex: 1; min-width: 200px; font-weight: 600; color: var(--c-primary-dark); }
.control-buttons { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Hand ---------- */
.hand-area {
    background: var(--c-card);
    border-radius: 14px;
    padding: 12px 16px;
    box-shadow: var(--shadow-sm);
}
.hand-area h3 { font-size: 1rem; margin-bottom: 10px; color: var(--c-primary-dark); }
.hand-area h3 small { font-weight: 400; color: var(--c-muted); font-size: 0.8rem; }
.hand { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.hand-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 10px 4px;
    border-radius: 10px;
    border: 2px solid;
    background: #fff;
    cursor: pointer;
    font-family: inherit;
    color: var(--c-text);
    transition: transform 0.15s, box-shadow 0.15s;
}
.hand-card.tier-2 { border-color: var(--t2-bd); background: var(--t2-bg); }
.hand-card.tier-3 { border-color: var(--t3-bd); background: var(--t3-bg); }
.hand-card small { font-size: 0.7rem; color: var(--c-muted); }
.hand-card .eats { color: var(--c-text); }
.hand-card:hover:not(:disabled) { transform: translateY(-4px); box-shadow: var(--shadow-md); }
.hand-card.selected { transform: translateY(-8px); box-shadow: 0 0 0 4px #1e88e5, var(--shadow-md); }
.hand-card:disabled { cursor: default; }
.hand-card.used { opacity: 0.35; filter: grayscale(1); }
.used-label {
    position: absolute; top: 40%;
    background: #455a64; color: #fff;
    font-size: 0.75rem; padding: 1px 8px; border-radius: 4px;
    transform: rotate(-12deg);
}

/* ---------- Side panel ---------- */
.side-panel { display: flex; flex-direction: column; gap: 14px; }
.energy-card, .event-feed-card {
    background: var(--c-card);
    border-radius: 14px;
    padding: 14px;
    box-shadow: var(--shadow-sm);
}
.energy-card h3, .event-feed-card h3 { font-size: 1rem; color: var(--c-primary-dark); margin-bottom: 10px; }
.mini-pyramid { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-bottom: 10px; }
.pyr { color: #fff; font-size: 0.74rem; font-weight: 600; text-align: center; padding: 3px 0; border-radius: 4px; }
.pyr-1 { width: 100%; background: #558b2f; }
.pyr-2 { width: 78%; background: var(--t1); }
.pyr-3 { width: 56%; background: var(--t2); }
.pyr-4 { width: 36%; background: var(--t3); }
.energy-list { display: flex; flex-direction: column; gap: 8px; max-height: 300px; overflow-y: auto; }
.energy-row { border-left: 4px solid; border-radius: 6px; padding: 6px 8px; font-size: 0.82rem; }
.energy-row.tier-2 { border-color: var(--t2); background: var(--t2-bg); }
.energy-row.tier-3 { border-color: var(--t3); background: var(--t3-bg); }
.er-title { display: flex; align-items: center; gap: 4px; font-weight: 700; flex-wrap: wrap; }
.er-title .sp-icon { width: 22px; height: 22px; font-size: 18px; }
.er-calc .gain { color: #e65100; }
.muted { color: var(--c-muted); font-size: 0.85rem; }

.status-banner {
    background: #e0f2f1;
    color: var(--c-primary-dark);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 0.88rem;
    font-weight: 600;
    margin-bottom: 8px;
}
.event-log-list { max-height: 280px; overflow-y: auto; display: flex; flex-direction: column; gap: 5px; }
.log-item { font-size: 0.8rem; padding: 5px 8px; border-radius: 6px; background: #f5f5f5; border-left: 3px solid #b0bec5; }
.log-predation { border-color: #43a047; background: #f1f8e9; }
.log-hazard { border-color: #e53935; background: #ffebee; }
.log-season { border-color: #ff8f00; background: #fff8e1; }
.log-miss { border-color: #90a4ae; color: var(--c-muted); }
.ptag { color: var(--pc); font-weight: 700; }

/* ---------- Modals ---------- */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
    padding: 16px;
}
.modal-card {
    background: #fff;
    border-radius: 16px;
    max-width: 760px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 20px;
    background: var(--c-primary-dark); color: #fff;
}
.modal-header h2 { font-size: 1.1rem; }
.modal-close-btn { background: none; border: none; color: #fff; font-size: 1.8rem; cursor: pointer; line-height: 1; }
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-footer { padding: 12px 20px; border-top: 1px solid #eceff1; text-align: right; }
.rule-section { margin-bottom: 16px; }
.rule-section h3 { color: var(--c-primary-dark); font-size: 1rem; margin-bottom: 6px; }
.rule-section p, .rule-section li { font-size: 0.9rem; }
.rule-section ul, .rule-section ol { padding-left: 22px; display: flex; flex-direction: column; gap: 4px; }
.rules-table-wrapper { overflow-x: auto; margin: 8px 0; }
.rules-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.rules-table th, .rules-table td { border: 1px solid #cfd8dc; padding: 6px 8px; text-align: center; }
.rules-table th { background: #e0f2f1; }

.victory-header { text-align: center; padding: 18px; background: linear-gradient(135deg, #ffb300, #ff8f00); color: #fff; }
.victory-icon { font-size: 2.4rem; }
.victory-body { padding: 16px 20px; overflow-y: auto; }
.victory-body > p { font-weight: 600; margin-bottom: 8px; }
.energy-summary { margin-top: 12px; background: #fff8e1; border-radius: 10px; padding: 12px; font-size: 0.88rem; }
.energy-summary h3 { font-size: 1rem; margin-bottom: 6px; }
.energy-summary .insight { margin-top: 8px; color: #e65100; font-weight: 600; }

.game-footer { text-align: center; padding: 14px; color: var(--c-muted); font-size: 0.8rem; }

/* ---------- Animations ---------- */
@keyframes pop { from { transform: scale(0.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes flipIn { from { transform: rotateY(90deg); } to { transform: rotateY(0); } }
@keyframes shake { 0% { transform: rotate(-12deg); } 50% { transform: rotate(12deg); } 100% { transform: rotate(-12deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
    .board-layout { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    .game-container { padding: 10px; }
    .game-header { padding: 12px; }
    .header-main h1 { font-size: 1.15rem; }
    .board { padding: 6px; gap: 4px 5px; }
    .cell { padding: 5px; min-height: 96px; }
    .cell-title small { display: none; }
    .sp-icon { width: 26px; height: 26px; font-size: 22px; }
    .die { width: 24px; height: 24px; font-size: 14px; }
    .die svg { width: 18px; height: 18px; }
    .chain-header { font-size: 0.75rem; }
    .hand { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .score-card { min-width: 120px; padding: 8px 10px; }
}
