:root {
    --bg: #f5efe6;
    --card: #ffffff;
    --ink: #2a2a2a;
    --muted: #6b6b6b;
    --accent: #c0392b;
    --accent-soft: #f4d4cf;
    --green: #2e8b57;
    --green-soft: #d4ebd9;
    --gold: #b8860b;
    --border: #e3dccf;
    --shadow: 0 6px 24px rgba(40, 30, 10, 0.08);
}

* { box-sizing: border-box; }

body, html {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.5;
    min-height: 100%;
}

.game {
    max-width: 880px;
    margin: 0 auto;
    padding: 40px 24px 64px;
}

.hero h1 {
    margin: 0 0 8px;
    font-size: 2rem;
    letter-spacing: -0.01em;
}

.hero .version {
    color: var(--accent);
    font-size: 0.9rem;
    font-weight: 600;
    vertical-align: super;
}

.hero .tagline {
    color: var(--muted);
    font-style: italic;
    margin: 0 0 16px;
}

.hero .rules {
    background: var(--card);
    border: 1px solid var(--border);
    border-left: 4px solid var(--gold);
    border-radius: 6px;
    padding: 12px 16px;
    margin: 0 0 12px;
    font-size: 0.95rem;
}

.hero .note {
    background: #fff8e6;
    border: 1px solid #f0e2b6;
    border-left: 4px solid var(--accent);
    border-radius: 6px;
    padding: 10px 14px;
    margin: 0 0 16px;
    font-size: 0.92rem;
}

.scenario-picker {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 14px;
    margin: 0 0 28px;
    font-size: 0.95rem;
}

.scenario-picker label {
    font-weight: 600;
    color: var(--muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.scenario-picker select {
    flex: 1;
    padding: 8px 10px;
    font-size: 0.95rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
    cursor: pointer;
}

.scenario-picker select:focus {
    outline: 2px solid var(--gold);
    outline-offset: 1px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    margin-bottom: 20px;
}

.stat {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    box-shadow: var(--shadow);
}

.stat .label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 4px;
}

.stat .value {
    font-size: 1.15rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.stat.highlight {
    background: linear-gradient(135deg, #fffaf0, #fff5e1);
    border-color: var(--gold);
}

.chart-wrap {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 16px 16px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    height: 340px;
    position: relative;
}

.chart-caption {
    margin: 0 0 6px;
    font-size: 0.82rem;
    color: var(--muted);
    font-weight: 600;
    text-align: center;
}

#chart {
    width: 100% !important;
    height: calc(100% - 22px) !important;
}

.actions {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.qty-label {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
    font-weight: 600;
}

.qty-label input {
    width: 110px;
    padding: 8px 10px;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-variant-numeric: tabular-nums;
}

.qty-label .hint {
    color: var(--muted);
    font-weight: 400;
    font-size: 0.85rem;
}

.buttons {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
}

.btn {
    padding: 12px 16px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.05s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.btn:active:not(:disabled) { transform: translateY(0); }

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

.btn-buy   { background: var(--green-soft); color: var(--green); }
.btn-buy:hover:not(:disabled) { background: #c4e1cc; }

.btn-sell  { background: var(--accent-soft); color: var(--accent); }
.btn-sell:hover:not(:disabled) { background: #efc1ba; }

.btn-hold  { background: #eee; color: #555; }
.btn-hold:hover:not(:disabled) { background: #e2e2e2; }

.btn-replay {
    background: var(--ink);
    color: white;
}

.btn-replay:hover:not(:disabled) { background: #444; }

.log-wrap {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    box-shadow: var(--shadow);
}

.log-wrap h3 {
    margin: 0 0 10px;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.log {
    list-style: none;
    padding: 0;
    margin: 0;
    min-height: 200px;
    column-count: 2;
    column-gap: 20px;
    font-size: 0.92rem;
    font-variant-numeric: tabular-nums;
}

.log li {
    padding: 6px 4px;
    border-bottom: 1px dashed var(--border);
    display: flex;
    justify-content: space-between;
    gap: 12px;
    break-inside: avoid;
    -webkit-column-break-inside: avoid;
    page-break-inside: avoid;
}

.log li:last-child { border-bottom: none; }

.log .tag {
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: 999px;
}

.log .tag-buy  { background: var(--green-soft); color: var(--green); }
.log .tag-sell { background: var(--accent-soft); color: var(--accent); }
.log .tag-hold { background: #eee; color: #666; }

.debrief {
    margin-top: 8px;
}

/* Every debrief panel — performance, history, AI, fvpv — shares the same
   card chrome: rounded corners, light border, soft shadow, 16px bottom gap. */
.collapsible-block,
.history-panel,
.fvpv-panel {
    margin: 0 0 16px;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.collapsible-block {
    background: var(--card);
    border: 1px solid var(--border);
    padding: 0;
}

.performance-collapsible {
    border-left: 4px solid var(--accent);
}

.collapsible-summary {
    cursor: pointer;
    padding: 16px 20px;
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--accent);
    list-style: none;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 10px;
}

.collapsible-summary::-webkit-details-marker { display: none; }

.collapsible-summary::before {
    content: '▸';
    display: inline-block;
    color: var(--muted);
    font-size: 0.85em;
    transition: transform 0.2s ease;
    width: 1em;
    text-align: center;
}

details[open] > .collapsible-summary::before {
    transform: rotate(90deg);
}

.collapsible-summary:hover {
    background: rgba(0,0,0,0.02);
    border-radius: 8px 8px 0 0;
}

details[open] > .collapsible-summary:hover {
    border-radius: 8px 8px 0 0;
}

.collapsible-content {
    padding: 0 20px 20px;
}

.ai-collapsible .collapsible-summary {
    color: #2a3f00;
}

.ai-collapsible {
    background: linear-gradient(180deg, #f4faef 0%, #ebf3e3 100%);
    border: 1px solid #c8dab0;
    border-left: 4px solid #76b900;
}

.reveal-btn {
    background: white;
    border: 1px dashed #8a9bb8;
    border-radius: 4px;
    padding: 3px 12px;
    cursor: pointer;
    color: #5a6b88;
    font-size: 0.85rem;
    font-family: inherit;
    font-style: italic;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.reveal-btn:hover:not(.revealed) {
    background: #f0f4fc;
    border-color: #3366cc;
    color: #3366cc;
}

.reveal-btn.revealed {
    background: transparent;
    border: none;
    color: var(--ink);
    font-style: normal;
    font-weight: 600;
    cursor: default;
    padding: 3px 0;
    font-size: 0.92rem;
    font-variant-numeric: tabular-nums;
}

.fvpv-hint {
    margin: 0 0 12px;
    font-size: 0.85rem;
    color: var(--muted);
    font-style: italic;
}

#debrief-summary {
    font-size: 1.05rem;
}

.debrief-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 16px 0 4px;
}

.debrief-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 14px;
}

.debrief-card .label {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 6px;
}

.debrief-card .value {
    font-size: 1.3rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.debrief-card.you { border-left: 4px solid var(--gold); }
.debrief-card.peak { border-left: 4px solid var(--green); }
.debrief-card.held { border-left: 4px solid var(--accent); }
.debrief-card.cashed { border-left: 4px solid var(--muted); }

.history-panel {
    padding: 18px 20px;
    background: #fbf6ec;
    border: 1px solid var(--border);
    border-left: 4px solid var(--gold);
}

.history-panel h3 {
    margin: 0 0 12px;
    color: var(--ink);
    font-size: 1.1rem;
}

.history-facts {
    margin: 0 0 10px;
    padding-left: 20px;
}

.history-facts li {
    margin-bottom: 8px;
    line-height: 1.5;
    font-size: 0.93rem;
}

.history-facts li:last-child { margin-bottom: 0; }

.history-link {
    margin: 8px 0 0;
    font-size: 0.9rem;
}

.history-link a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

.history-link a:hover { text-decoration: underline; }

.ai-intro {
    margin: 0 0 14px;
    line-height: 1.55;
    font-size: 0.95rem;
}

.ai-bullets {
    margin: 0 0 18px;
    padding-left: 20px;
}

.ai-bullets li {
    margin-bottom: 10px;
    line-height: 1.5;
    font-size: 0.92rem;
}

.nvda-chart-wrap {
    background: white;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 16px;
    margin: 0 0 18px;
    height: 260px;
    position: relative;
}

.nvda-caption {
    margin: 0 0 6px;
    font-size: 0.82rem;
    color: var(--muted);
    text-align: center;
}

#nvda-chart {
    width: 100% !important;
    height: calc(100% - 24px) !important;
}

.reflection-q {
    display: block;
    margin: 14px 0 0;
    padding: 14px 16px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-weight: 600;
    color: var(--ink);
    line-height: 1.5;
    font-size: 0.95rem;
}

.fvpv-panel {
    padding: 18px 20px;
    background: #eef3fb;
    border: 1px solid #c8d4e8;
    border-left: 4px solid #3366cc;
}

.fvpv-panel h3 {
    margin: 0 0 10px;
    font-size: 1.1rem;
    color: #1d2f57;
}

.fvpv-explain {
    margin: 0 0 14px;
    font-size: 0.93rem;
    line-height: 1.5;
}

.fvpv-explain code {
    background: white;
    padding: 1px 6px;
    border-radius: 3px;
    border: 1px solid #d0dbed;
    font-size: 0.92rem;
}

.fvpv-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 6px;
    overflow: hidden;
    font-size: 0.92rem;
    margin: 0 0 12px;
}

.fvpv-table th, .fvpv-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
}

.fvpv-table th {
    background: #f4f8ff;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.fvpv-table th:nth-child(2),
.fvpv-table td:nth-child(2),
.fvpv-table th:nth-child(3),
.fvpv-table td:nth-child(3) {
    text-align: right;
}

.fvpv-table tr:last-child td { border-bottom: none; }

.fvpv-note {
    margin: 0;
    font-size: 0.88rem;
    color: var(--muted);
    font-style: italic;
}

.btn-fvpv {
    background: #d8e2f3;
    color: #1d2f57;
}

.btn-fvpv:hover:not(:disabled) { background: #c8d4e8; }

.debrief-buttons {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    flex-wrap: wrap;
    align-items: stretch;
}

.debrief-buttons .btn {
    padding: 12px 20px;
    font-size: 0.95rem;
    margin: 0;
}

.btn-print {
    background: #eee;
    color: #444;
}

.btn-print:hover:not(:disabled) { background: #e0e0e0; }

@media print {
    .scenario-picker, .actions, .footer, .debrief-buttons { display: none !important; }
    .game { max-width: none; padding: 10px; }
    .chart-wrap, .nvda-chart-wrap { page-break-inside: avoid; }
}

/* FEEDBACK BUTTON + MODAL (ported from welfare-lab) */
.feedback-btn {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 90;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 999px;
    padding: 0.65rem 1.2rem;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: transform 0.18s, background 0.18s, box-shadow 0.18s;
}
.feedback-btn:hover {
    background: #9c2e22;
    transform: translateY(-1px);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
}
.feedback-btn:focus-visible {
    outline: 3px solid var(--ink);
    outline-offset: 3px;
}
.feedback-btn-icon { font-size: 1rem; line-height: 1; }

.feedback-modal {
    position: fixed; inset: 0; z-index: 200;
    display: flex; align-items: center; justify-content: center;
    padding: 1rem;
}
.feedback-modal[hidden] { display: none; }
.feedback-backdrop {
    position: absolute; inset: 0;
    background: rgba(0, 0, 0, 0.5);
    animation: fb-fade 0.18s ease;
}
.feedback-card {
    position: relative;
    background: white;
    border-radius: 8px;
    padding: 1.5rem 1.5rem 1.25rem;
    max-width: 540px;
    width: 100%;
    max-height: 92vh;
    overflow-y: auto;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    animation: fb-fade 0.22s ease;
}
@keyframes fb-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.feedback-close {
    position: absolute;
    top: 0.75rem;
    right: 0.95rem;
    background: transparent;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    color: #888;
    padding: 0.2rem 0.5rem;
    font-family: inherit;
    border-radius: 6px;
}
.feedback-close:hover { color: var(--ink); background: #f0f0f0; }
.feedback-card h2 {
    color: var(--ink);
    font-size: 1.2rem;
    margin: 0;
    padding-right: 1.5rem;
}
.feedback-sub {
    color: #555;
    font-size: 0.85rem;
    line-height: 1.45;
    margin: 0;
}
.feedback-cat {
    display: flex;
    gap: 0.95rem 1rem;
    flex-wrap: wrap;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 0.85rem 0.6rem;
    margin: 0;
}
.feedback-cat legend {
    padding: 0 0.4rem;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    font-weight: 600;
}
.feedback-cat label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    color: #555;
    cursor: pointer;
}
.feedback-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: -0.4rem;
}
#feedback-text {
    width: 100%;
    box-sizing: border-box;
    border: 1.5px solid #ccc;
    border-radius: 8px;
    padding: 0.65rem 0.75rem;
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
    min-height: 120px;
}
#feedback-text:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}
.feedback-context {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.45rem 0.75rem;
    font-size: 0.8rem;
    color: #555;
}
.feedback-context summary {
    cursor: pointer;
    color: var(--muted);
    font-size: 0.78rem;
    list-style: none;
}
.feedback-context summary::-webkit-details-marker { display: none; }
.feedback-context summary::before {
    content: '▸ ';
    color: #aaa;
}
.feedback-context[open] summary::before { content: '▾ '; }
.feedback-context pre {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.72rem;
    color: #555;
    margin-top: 0.55rem;
    white-space: pre-wrap;
    background: #f7f4ee;
    padding: 0.55rem 0.7rem;
    border-radius: 6px;
    max-height: 160px;
    overflow-y: auto;
}
.feedback-actions {
    display: flex;
    gap: 0.55rem;
    justify-content: flex-end;
    flex-wrap: wrap;
    margin-top: 0.2rem;
}
.feedback-action-btn {
    background: white;
    color: var(--ink);
    border: 1.5px solid var(--border);
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.feedback-action-btn:hover { background: #f5f0e6; border-color: #c8bfae; }
.feedback-action-primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}
.feedback-action-primary:hover { background: #9c2e22; border-color: #9c2e22; color: white; }
.feedback-hint {
    font-size: 0.72rem;
    color: var(--muted);
    text-align: center;
    line-height: 1.4;
    margin: 0;
}
.feedback-hint a { color: var(--accent); font-weight: 600; }
.feedback-hint em { font-style: normal; font-weight: 600; color: #555; }
.feedback-toast {
    position: fixed;
    bottom: 5.5rem;
    right: 1.5rem;
    z-index: 250;
    background: var(--ink);
    color: white;
    padding: 0.55rem 0.95rem;
    border-radius: 8px;
    font-size: 0.82rem;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
    animation: fb-fade 0.18s ease;
}
.feedback-toast[hidden] { display: none; }

@media print {
    .feedback-btn, .feedback-modal, .feedback-toast { display: none !important; }
}

@media (max-width: 640px) {
    .feedback-btn { bottom: 1rem; right: 1rem; padding: 0.55rem 0.95rem; font-size: 0.78rem; }
    .feedback-card { padding: 1.2rem; }
    .feedback-actions { flex-direction: column-reverse; }
    .feedback-actions .btn { width: 100%; }
}

.hidden { display: none; }

.footer {
    margin-top: 32px;
    text-align: center;
    font-size: 0.85rem;
}

.footer a {
    color: var(--muted);
    text-decoration: none;
}

.footer a:hover { color: var(--accent); }

@media (max-width: 640px) {
    .game { padding: 20px 14px 40px; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    .stat.highlight { grid-column: 1 / -1; }
    .chart-wrap { height: 280px; }
    .buttons { grid-template-columns: 1fr; }
    .debrief-grid { grid-template-columns: 1fr; }
    .debrief-buttons { flex-direction: column; }
    .debrief-buttons .btn { width: 100%; }
    .log { column-count: 1; }
    .collapsible-summary { font-size: 1.15rem; padding: 14px 16px; }
    .collapsible-content { padding: 0 16px 16px; }
    .history-panel, .fvpv-panel { padding: 16px; }
    .fvpv-table { font-size: 0.85rem; }
    .fvpv-table th, .fvpv-table td { padding: 6px 8px; }
}
