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

:root {
    --scale: 1;
    --plate-size-45: calc(clamp(55px, 16vw, 100px) * 1.15 * var(--scale));
    --plate-size-35: calc(clamp(48px, 14vw, 88px) * 1.15 * var(--scale));
    --plate-size-25: calc(clamp(42px, 12vw, 76px) * 1.15 * var(--scale));
    --plate-size-10: calc(clamp(36px, 10vw, 60px) * 1.15 * var(--scale));
    --plate-size-5: calc(clamp(30px, 8vw, 48px) * 1.15 * var(--scale));
    --plate-size-min: calc(clamp(26px, 7vw, 38px) * 1.15 * var(--scale));
    --plate-percent-1: calc(clamp(40px, 11vw, 65px) * 1.15 * var(--scale));
    --plate-percent-2: calc(clamp(35px, 10vw, 58px) * 1.15 * var(--scale));
    --plate-percent-3: calc(clamp(32px, 9vw, 52px) * 1.15 * var(--scale));
    --plate-percent-4: calc(clamp(28px, 8vw, 44px) * 1.15 * var(--scale));
    --plate-percent-5: calc(clamp(24px, 7vw, 38px) * 1.15 * var(--scale));
    --plate-percent-6: calc(clamp(22px, 6vw, 32px) * 1.15 * var(--scale));
    --plate-percent-font: calc(clamp(0.65rem, 1.8vw, 0.85rem) * 1.15 * var(--scale));
    --base-font: calc(clamp(14px, 4vw, 18px) * 1.15 * var(--scale));
    --success: #4ade80;
    --warning: #fbbf24;
    --danger: #ef4444;
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --text-primary: #eaeaea;
    --text-secondary: #a0a0a0;
    --text-muted: #6b6b6b;
    --accent: #e94560;
    --accent-hover: #ff6b6b;
    --plate-1: #dc2626;
    --plate-2: #3b82f6;
    --plate-3: #eab308;
    --plate-4: #22c55e;
    --plate-5: #e5e7eb;
    --plate-6: #9ca3af;
    --plate-text-1: #ffffff;
    --plate-text-2: #ffffff;
    --plate-text-3: #171717;
    --plate-text-4: #171717;
    --plate-text-5: #171717;
    --plate-text-6: #171717;
}

[data-theme="midnight-blue"] {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --text-primary: #eaeaea;
    --text-secondary: #a0a0a0;
    --text-muted: #6b6b6b;
    --accent: #e94560;
    --accent-hover: #ff6b6b;
    --plate-1: #dc2626;
    --plate-2: #3b82f6;
    --plate-3: #eab308;
    --plate-4: #22c55e;
    --plate-5: #e5e7eb;
    --plate-6: #9ca3af;
    --plate-text-1: #ffffff;
    --plate-text-2: #ffffff;
    --plate-text-3: #171717;
    --plate-text-4: #171717;
    --plate-text-5: #171717;
    --plate-text-6: #171717;
}

[data-theme="charcoal-red"] {
    --bg-primary: #0d0d0d;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #2a2a2a;
    --text-primary: #e5e5e5;
    --text-secondary: #9a9a9a;
    --text-muted: #5a5a5a;
    --accent: #dc2626;
    --accent-hover: #ef4444;
    --plate-1: #ef4444;
    --plate-2: #60a5fa;
    --plate-3: #fbbf24;
    --plate-4: #4ade80;
    --plate-5: #d1d5db;
    --plate-6: #9ca3af;
    --plate-text-1: #ffffff;
    --plate-text-2: #ffffff;
    --plate-text-3: #171717;
    --plate-text-4: #171717;
    --plate-text-5: #171717;
    --plate-text-6: #171717;
}

[data-theme="classic-light"] {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e5e5e5;
    --text-primary: #1a1a1a;
    --text-secondary: #525252;
    --text-muted: #a0a0a0;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --plate-1: #b91c1c;
    --plate-2: #1e40af;
    --plate-3: #eab308;
    --plate-4: #22c55e;
    --plate-5: #6b7280;
    --plate-6: #171717;
    --plate-text-1: #ffffff;
    --plate-text-2: #ffffff;
    --plate-text-3: #171717;
    --plate-text-4: #ffffff;
    --plate-text-5: #ffffff;
    --plate-text-6: #ffffff;
}

[data-theme="barbie-pink"] {
    --bg-primary: #fff0f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #ffe4ec;
    --text-primary: #1f1f1f;
    --text-secondary: #4a4a4a;
    --text-muted: #9ca3af;
    --accent: #ec4899;
    --accent-hover: #f472b6;
    --plate-1: #b91c1c;
    --plate-2: #1e40af;
    --plate-3: #eab308;
    --plate-4: #22c55e;
    --plate-5: #6b7280;
    --plate-6: #171717;
    --plate-text-1: #ffffff;
    --plate-text-2: #ffffff;
    --plate-text-3: #171717;
    --plate-text-4: #ffffff;
    --plate-text-5: #ffffff;
    --plate-text-6: #ffffff;
}

html {
    font-size: var(--base-font);
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.view {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: clamp(12px, 4vw, 24px);
    padding-bottom: clamp(70px, 20vw, 110px);
}

.view.active {
    display: block;
}

.weight-input-section {
    text-align: center;
    margin-bottom: clamp(16px, 5vw, 30px);
}

.weight-input-section label {
    font-size: clamp(1rem, 4vw, 1.3rem);
    color: var(--text-secondary);
    margin-bottom: clamp(6px, 2vw, 12px);
    display: block;
}

.input-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(8px, 2vw, 12px);
}

.weight-input-section input[type="number"] {
    font-size: clamp(1.2rem, 4vw, 1.6rem);
    width: clamp(70px, 20vw, 110px);
    padding: clamp(6px, 2vw, 12px);
    text-align: center;
    background: var(--bg-secondary);
    border: 2px solid var(--bg-tertiary);
    border-radius: clamp(8px, 2vw, 14px);
    color: var(--text-primary);
    outline: none;
    -moz-appearance: textfield;
}

.weight-input-section input[type="number"]::-webkit-outer-spin-button,
.weight-input-section input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.weight-input-section input[type="number"]:focus {
    border-color: var(--accent);
}

.weight-input-section .unit-label {
    font-size: clamp(1rem, 3vw, 1.2rem);
    color: var(--text-secondary);
}

.results-section {
    flex: 1;
}

.main-result {
    background: var(--bg-secondary);
    border-radius: clamp(12px, 3vw, 20px);
    padding: clamp(14px, 4vw, 24px);
    margin-bottom: clamp(14px, 4vw, 24px);
    text-align: center;
}

.result-weight {
    font-size: clamp(2.2rem, 8vw, 3.5rem);
    font-weight: bold;
    margin-bottom: clamp(12px, 3vw, 20px);
}

.result-weight .unit-label {
    font-size: clamp(1.2rem, 4vw, 1.6rem);
    font-weight: normal;
}

.plate-display {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: clamp(6px, 2vw, 12px);
    min-height: clamp(50px, 15vw, 80px);
}

.plate {
    border-radius: clamp(8px, 2vw, 14px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

.plate.position-1 {
    width: var(--plate-size-45);
    height: var(--plate-size-45);
    font-size: clamp(1rem, 3vw, 1.4rem);
    background: var(--plate-1, #dc2626);
    color: var(--plate-text-1, #ffffff);
}

.plate.position-2 {
    width: var(--plate-size-35);
    height: var(--plate-size-35);
    font-size: clamp(0.9rem, 2.8vw, 1.3rem);
    background: var(--plate-2, #3b82f6);
    color: var(--plate-text-2, #ffffff);
}

.plate.position-3 {
    width: var(--plate-size-25);
    height: var(--plate-size-25);
    font-size: clamp(0.85rem, 2.6vw, 1.2rem);
    background: var(--plate-3, #eab308);
    color: var(--plate-text-3, #171717);
    text-shadow: none;
}

.plate.position-4 {
    width: var(--plate-size-10);
    height: var(--plate-size-10);
    font-size: clamp(0.8rem, 2.4vw, 1.1rem);
    background: var(--plate-4, #22c55e);
    color: var(--plate-text-4, #171717);
    text-shadow: none;
}

.plate.position-5 {
    width: var(--plate-size-5);
    height: var(--plate-size-5);
    font-size: clamp(0.75rem, 2.2vw, 1rem);
    background: var(--plate-5, #e5e7eb);
    color: var(--plate-text-5, #171717);
    text-shadow: none;
}

.plate.position-6 {
    width: var(--plate-size-min);
    height: var(--plate-size-min);
    font-size: clamp(0.7rem, 2vw, 0.9rem);
    background: var(--plate-6, #9ca3af);
    color: var(--plate-text-6, #171717);
}

.percentage-plates .plate {
    font-size: var(--plate-percent-font);
}

.percentage-plates .plate.position-1 {
    width: var(--plate-percent-1);
    height: var(--plate-percent-1);
}

.percentage-plates .plate.position-2 {
    width: var(--plate-percent-2);
    height: var(--plate-percent-2);
}

.percentage-plates .plate.position-3 {
    width: var(--plate-percent-3);
    height: var(--plate-percent-3);
}

.percentage-plates .plate.position-4 {
    width: var(--plate-percent-4);
    height: var(--plate-percent-4);
}

.percentage-plates .plate.position-5 {
    width: var(--plate-percent-5);
    height: var(--plate-percent-5);
}

.percentage-plates .plate.position-6 {
    width: var(--plate-percent-6);
    height: var(--plate-percent-6);
}

.plate.custom-weight {
    width: var(--plate-size-min);
    height: var(--plate-size-min);
    font-size: clamp(0.7rem, 2vw, 0.9rem);
    background: var(--plate-6);
    color: white;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

.percentage-plates .plate.custom-weight {
    width: var(--plate-percent-6);
    height: var(--plate-percent-6);
}

.warning-message {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid var(--danger);
    border-radius: clamp(6px, 2vw, 10px);
    padding: clamp(8px, 2vw, 14px);
    text-align: center;
    margin-bottom: clamp(12px, 3vw, 20px);
    color: var(--danger);
    font-size: clamp(0.9rem, 2.8vw, 1rem);
}

.warning-message.hidden {
    display: none;
}

.warning-hint {
    margin-top: 0.5em;
    font-size: 0.85em;
    opacity: 0.75;
}

.percentages-section {
    background: var(--bg-secondary);
    border-radius: clamp(12px, 3vw, 18px);
    padding: clamp(12px, 3vw, 20px);
}

.percentages-section h3 {
    color: var(--text-secondary);
    font-size: clamp(0.9rem, 2.8vw, 1.1rem);
    margin-bottom: clamp(10px, 2vw, 16px);
}

.percentage-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: clamp(10px, 2vw, 16px) 0;
    border-bottom: 1px solid var(--bg-tertiary);
}

.percentage-row:last-child {
    border-bottom: none;
}

.percentage-label {
    font-size: clamp(1rem, 3vw, 1.3rem);
    color: var(--text-secondary);
}

.percentage-weight {
    font-size: clamp(1.2rem, 4vw, 1.6rem);
    font-weight: bold;
}

.percentage-plates {
    display: flex;
    align-items: center;
    gap: clamp(4px, 1vw, 8px);
    flex-wrap: wrap;
    justify-content: flex-end;
}

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: var(--bg-secondary);
    border-top: 1px solid var(--bg-tertiary);
    padding-bottom: env(safe-area-inset-bottom);
    font-size: 16px;
}

.nav-btn {
    flex: 1;
    padding: 18px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.2s, background-color 0.2s;
}

.nav-btn.active {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.nav-btn:active {
    background: var(--bg-tertiary);
}

.settings-section {
    background: var(--bg-secondary);
    border-radius: clamp(12px, 3vw, 18px);
    padding: clamp(12px, 3vw, 20px);
    margin-bottom: clamp(12px, 3vw, 20px);
}

.settings-section h2 {
    font-size: clamp(1.1rem, 3vw, 1.3rem);
    margin-bottom: clamp(10px, 2vw, 16px);
    color: var(--text-primary);
}

.setting-row {
    display: flex;
    align-items: center;
    gap: clamp(6px, 2vw, 12px);
}

.settings-section input[type="number"] {
    font-size: clamp(1.2rem, 4vw, 1.6rem);
    width: clamp(70px, 20vw, 110px);
    padding: clamp(6px, 2vw, 12px);
    text-align: center;
    background: var(--bg-secondary);
    border: 2px solid var(--bg-tertiary);
    border-radius: clamp(8px, 2vw, 14px);
    color: var(--text-primary);
    outline: none;
    -moz-appearance: textfield;
}

.settings-section input[type="number"]::-webkit-outer-spin-button,
.settings-section input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.help-text {
    font-size: clamp(0.8rem, 2.5vw, 0.9rem);
    color: var(--text-muted);
    margin-bottom: clamp(10px, 2vw, 16px);
}

.unit-toggle {
    padding: clamp(10px, 3vw, 14px) clamp(20px, 5vw, 32px);
    font-size: clamp(1rem, 3vw, 1.2rem);
    font-weight: 600;
    background: var(--bg-tertiary);
    border: none;
    border-radius: clamp(6px, 2vw, 10px);
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.2s;
}

.unit-toggle:active {
    background: var(--accent);
}

.plate-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: clamp(10px, 2vw, 14px) 0;
    border-bottom: 1px solid var(--bg-tertiary);
}

.plate-item:last-child {
    border-bottom: none;
}

.plate-info {
    display: flex;
    align-items: center;
    gap: clamp(8px, 2vw, 14px);
}

.plate-color-indicator {
    width: clamp(24px, 6vw, 32px);
    height: clamp(24px, 6vw, 32px);
    border-radius: clamp(4px, 1vw, 6px);
}

.plate-weight {
    font-size: clamp(1rem, 3vw, 1.2rem);
    font-weight: 500;
}

.plate-controls {
    display: flex;
    align-items: center;
    gap: clamp(6px, 1.5vw, 10px);
}

.plate-controls button {
    width: clamp(38px, 10vw, 48px);
    height: clamp(38px, 10vw, 48px);
    border: none;
    border-radius: clamp(6px, 2vw, 10px);
    font-size: clamp(1.2rem, 4vw, 1.6rem);
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

.plate-controls .decrement {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.plate-controls .increment {
    background: var(--accent);
    color: white;
}

.plate-controls button:active {
    opacity: 0.8;
}

.plate-count {
    font-size: clamp(1.1rem, 3vw, 1.4rem);
    font-weight: bold;
    min-width: clamp(24px, 6vw, 32px);
    text-align: center;
}

.add-plate-btn, .add-btn {
    width: 100%;
    padding: clamp(12px, 3vw, 16px);
    margin-top: clamp(10px, 2vw, 16px);
    background: transparent;
    border: 2px dashed var(--bg-tertiary);
    border-radius: clamp(8px, 2vw, 14px);
    color: var(--text-muted);
    font-size: clamp(0.9rem, 2.8vw, 1rem);
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.add-plate-btn:hover, .add-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.toggle-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    width: 100%;
}

.toggle-label span:first-child {
    font-size: clamp(0.9rem, 2.8vw, 1rem);
}

input[type="checkbox"] {
    display: none;
}

.toggle-slider {
    width: clamp(44px, 12vw, 56px);
    height: clamp(26px, 7vw, 32px);
    background: var(--bg-tertiary);
    border-radius: clamp(12px, 3vw, 16px);
    position: relative;
    transition: background 0.2s;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    width: clamp(20px, 5vw, 24px);
    height: clamp(20px, 5vw, 24px);
    background: var(--text-primary);
    border-radius: 50%;
    top: clamp(3px, 1vw, 4px);
    left: clamp(3px, 1vw, 4px);
    transition: transform 0.2s;
}

input[type="checkbox"]:checked + .toggle-slider {
    background: var(--accent);
}

input[type="checkbox"]:checked + .toggle-slider::after {
    transform: translateX(clamp(20px, 5vw, 24px));
}

.percentage-settings {
    margin-top: clamp(10px, 2vw, 16px);
}

.percentage-setting-item {
    display: flex;
    align-items: center;
    gap: clamp(6px, 2vw, 10px);
    margin-bottom: clamp(6px, 2vw, 10px);
}

.percentage-setting-item input {
    font-size: clamp(1rem, 3vw, 1.2rem);
    width: clamp(50px, 14vw, 70px);
    padding: clamp(6px, 2vw, 10px);
    text-align: center;
    background: var(--bg-secondary);
    border: 2px solid var(--bg-tertiary);
    border-radius: clamp(6px, 2vw, 10px);
    color: var(--text-primary);
    outline: none;
    -moz-appearance: textfield;
}

.percentage-setting-item input::-webkit-outer-spin-button,
.percentage-setting-item input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.percentage-setting-item .remove-btn {
    background: var(--danger);
    color: white;
    border: none;
    border-radius: clamp(4px, 1vw, 6px);
    width: clamp(32px, 8vw, 40px);
    height: clamp(32px, 8vw, 40px);
    cursor: pointer;
    font-size: clamp(1rem, 3vw, 1.3rem);
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: clamp(12px, 3vw, 18px);
    padding: clamp(16px, 4vw, 26px);
    width: 90%;
    max-width: 320px;
}

.modal-content h3 {
    margin-bottom: clamp(14px, 3vw, 20px);
    text-align: center;
    font-size: clamp(1.1rem, 3vw, 1.3rem);
}

.modal-field {
    margin-bottom: clamp(14px, 3vw, 20px);
}

.modal-field label {
    display: block;
    margin-bottom: clamp(6px, 2vw, 10px);
    color: var(--text-secondary);
    font-size: clamp(0.9rem, 2.5vw, 1rem);
}

.modal-field input {
    width: 100%;
    font-size: clamp(1.2rem, 4vw, 1.6rem);
    padding: clamp(8px, 2vw, 14px);
    text-align: center;
    background: var(--bg-secondary);
    border: 2px solid var(--bg-tertiary);
    border-radius: clamp(8px, 2vw, 14px);
    color: var(--text-primary);
    outline: none;
    -moz-appearance: textfield;
}

.modal-field input::-webkit-outer-spin-button,
.modal-field input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.modal-buttons {
    display: flex;
    gap: clamp(8px, 2vw, 12px);
}

.modal-buttons button {
    flex: 1;
    padding: clamp(10px, 3vw, 14px);
    border: none;
    border-radius: clamp(6px, 2vw, 10px);
    font-size: clamp(0.95rem, 3vw, 1.1rem);
    font-weight: 600;
    cursor: pointer;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.unable-text {
    color: var(--text-muted);
    font-style: italic;
    font-size: clamp(0.9rem, 2.5vw, 1rem);
}

.theme-section {
    margin-bottom: clamp(80px, 20vw, 120px);
}

.theme-toggle-btn {
    width: 100%;
    padding: clamp(16px, 4vw, 24px);
    background: var(--bg-tertiary);
    border: 2px solid var(--accent);
    border-radius: clamp(10px, 3vw, 16px);
    color: var(--text-primary);
    font-size: clamp(1rem, 3.5vw, 1.3rem);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(8px, 2vw, 12px);
}

.theme-toggle-btn:active {
    background: var(--accent);
    transform: scale(0.98);
}

.theme-preview {
    display: flex;
    gap: clamp(4px, 1vw, 8px);
    align-items: center;
    justify-content: center;
}

.scale-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(12px, 4vw, 24px);
}

.scale-btn {
    width: clamp(48px, 12vw, 64px);
    height: clamp(48px, 12vw, 64px);
    border: none;
    border-radius: clamp(8px, 2vw, 12px);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: clamp(1.5rem, 5vw, 2rem);
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

.scale-btn:active {
    background: var(--accent);
}

#scale-display {
    font-size: clamp(1.2rem, 4vw, 1.6rem);
    font-weight: 600;
    min-width: clamp(60px, 15vw, 80px);
    text-align: center;
}