:root {
    /* Color Palette */
    --color-bg: #111827;
    --color-surface: #1f2937;
    --color-border: #374151;
    --color-primary: #3B82F6;
    --color-primary-hover: #2563EB;
    --color-accent: #059669;
    --color-accent-hover: #047857;
    --color-gold: #D4AF37;
    --color-alert: #EF4444;
    --color-text-muted: #9CA3AF;

    /* Typography */
    --fs-floor-display: 2.25rem;
    --fs-h2: 1.25rem;
    --fs-h3: 1.125rem;
    --fs-btn-nav: 3.75rem;
    --fs-btn-key: 1.5rem;
    --fs-btn-primary: 0.875rem;
    --fs-btn-secondary: 0.875rem;
    --fs-btn-accent: 0.75rem;
    --fs-input-grid: 1.5rem;
    --fs-input-summary: 1rem;
    --fs-label-grid: 0.625rem;
    --fs-table-header: 0.625rem;
    --fs-table-cell: 1rem;
    --fs-table-cell-sm: 0.6875rem;
    --fs-history-header: 0.625rem;
    --fs-history-table: 10px;
    --fs-modal-title: 1.5rem;
}

/* Base Styles */
body {
    background-color: var(--color-bg);
    color: white;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
}

/* Dialog Animation */
dialog::backdrop {
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.2s ease-out;
}
dialog[open]::backdrop { opacity: 1; }
dialog {
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.2s ease-out, transform 0.2s ease-out;
}
dialog[open] {
    opacity: 1;
    transform: scale(1);
}

/* Typography */
#display-floor { font-size: var(--fs-floor-display); }
h2 { font-size: var(--fs-h2); }
h3 { font-size: var(--fs-h3); }
#confirm-message { font-size: var(--fs-h3); }
.modal-title-text { font-size: var(--fs-modal-title); }

/* Buttons */
.btn-primary {
    background-color: var(--color-primary);
    color: white;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    font-size: var(--fs-btn-primary);
    font-weight: bold;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    transition: background-color 0.2s;
    touch-action: manipulation;
}
.btn-primary:active { background-color: var(--color-primary-hover); }

.btn-secondary {
    background-color: var(--color-border);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 0.25rem;
    font-size: var(--fs-btn-secondary);
    font-weight: bold;
    transition: background-color 0.2s;
    touch-action: manipulation;
}
.btn-secondary:active { background-color: #4b5563; }

.btn-accent {
    background-color: var(--color-accent);
    color: white;
    padding: 0.5rem 0.75rem;
    border-radius: 0.25rem;
    font-size: var(--fs-btn-accent);
    font-weight: bold;
    transition: background-color 0.2s;
    touch-action: manipulation;
}
.btn-accent:active { background-color: var(--color-accent-hover); }

.nav-btn {
    font-size: var(--fs-btn-nav);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    color: white;
    opacity: 0.4;
    transition: opacity 0.2s;
    touch-action: manipulation;
}
.nav-btn:active { opacity: 1; }

/* Keypad Buttons */
.key-btn {
    background-color: var(--color-surface);
    color: white;
    font-size: var(--fs-btn-key);
    font-weight: bold;
    height: 3.2rem;
    border-radius: 0.5rem;
    border-bottom: 3px solid var(--color-border);
    transition: transform 0.1s, border-bottom-width 0.1s, background-color 0.1s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    touch-action: manipulation;
}
.key-btn:active {
    transform: translateY(2px);
    border-bottom-width: 0;
    background-color: #4b5563;
}
.key-slash { background-color: rgba(127, 29, 29, 0.8); color: #fecaca; border-color: #991b1b; }
.key-clear { background-color: rgba(30, 58, 138, 0.8); color: #bfdbfe; border-color: #1e40af; }
.key-clear-blue { background-color: rgba(30, 58, 138, 0.8); color: #bfdbfe; }
.key-next { background-color: #15803d; color: white; border-color: #14532d; }

/* Inputs */
input[type="text"], input[type="number"] {
    -webkit-appearance: none; appearance: none;
    text-align: center; caret-color: transparent; cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    touch-action: manipulation;
}
::placeholder { color: var(--color-text-muted); opacity: 0.6; font-size: 1.1rem; }

.input-grid-cell {
    color: var(--color-gold);
    text-shadow: 0 0 1px rgba(212, 175, 55, 0.3);
    font-size: var(--fs-input-grid);
    outline: none;
}
input.is-active {
    outline: none; border-color: var(--color-primary);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.4);
    background-color: #374151; transform: scale(1.05); z-index: 10;
}
input.is-alert { color: var(--color-alert); text-shadow: 0 0 1px rgba(239, 68, 68, 0.3); }

/* Text Utilities */
.text-gold {
    color: var(--color-gold); font-weight: 900;
    -webkit-text-stroke: 0.8px var(--color-gold);
    text-shadow: 1px 0 0 currentColor, -1px 0 0 currentColor, 0 1px 0 currentColor, 0 -1px 0 currentColor, 0 0 4px rgba(255, 215, 0, 0.5);
}
.text-needed { color: white; }
.text-order { color: #f87171; }
.text-distribution { color: #60a5fa; }
.text-muted { color: var(--color-text-muted); }
.text-muted-light { color: #d1d5db; }
.text-white-force { color: white !important; }

.title-item-bold {
    color: #ffffff;
    -webkit-text-stroke: 0.8px #000000;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* Summary Table */
.table-header-row { font-size: var(--fs-table-header); }
.summary-input {
    background-color: var(--color-surface); border: 1px solid var(--color-border);
    color: white; width: 100%; padding: 4px; border-radius: 4px; height: 36px;
    font-size: var(--fs-input-summary); font-weight: bold; text-align: center;
    outline: none;
}
.cell-standard { font-size: var(--fs-table-cell); }
.cell-small { font-size: var(--fs-table-cell-sm); }
.item-label { font-size: var(--fs-label-grid); }
.btn-distribute { font-size: 0.75rem; color: white; }

/* History UI */
.history-header { color: #e5e7eb; }
.history-header-row { color: #d1d5db; font-size: var(--fs-history-header); }
.history-content {
    max-height: 0; overflow: hidden; transition: max-height 0.15s ease-out;
    font-size: var(--fs-history-header);
}
.history-item.open .history-content { max-height: 500px; transition: max-height 0.15s ease-in; }
.history-arrow { transition: transform 0.15s; font-size: 0.75rem; color: var(--color-text-muted); }
.history-item.open .history-arrow { transform: rotate(180deg); }
.btn-copy-history { font-size: var(--fs-history-header); }

/* History Table */
.history-table {
    font-size: var(--fs-history-table); white-space: nowrap;
    border-collapse: collapse; width: 100%;
}
.history-table th, .history-table td {
    padding: 2px 4px; border: 1px solid #374151; text-align: center;
}
.history-table th { background-color: #1f2937; color: #9CA3AF; }
.history-table .text-gold { font-weight: normal; -webkit-text-stroke: 0; text-shadow: none; }

/* Scrollbar */
.custom-scrollbar { scrollbar-width: thin; scrollbar-color: var(--color-border) var(--color-bg); }
.custom-scrollbar::-webkit-scrollbar { width: 6px; height: 6px; }
.custom-scrollbar::-webkit-scrollbar-track { background: var(--color-bg); }
.custom-scrollbar::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }

/* Modal Content */
#modal-content table { font-size: 1.5rem; }
#modal-content table td { height: 3rem; }

/* Page Transition Animations (Faster: 0.07s) */
@keyframes slideOutLeft {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(-20%); opacity: 0; }
}
@keyframes slideInRight {
    from { transform: translateX(20%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes slideOutRight {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(20%); opacity: 0; }
}
@keyframes slideInLeft {
    from { transform: translateX(-20%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.anim-slide-out-left { animation: slideOutLeft 0.07s ease-in forwards; }
.anim-slide-in-right { animation: slideInRight 0.07s ease-out forwards; }
.anim-slide-out-right { animation: slideOutRight 0.07s ease-in forwards; }
.anim-slide-in-left { animation: slideInLeft 0.07s ease-out forwards; }