:root {
    --color-bg-primary: #1a1a1a;
    --color-bg-secondary: #2d2d2d;
    --color-bg-hover: #3a3a3a;
    --color-border: #404040;
    --color-border-light: #3a3a3a;
    --color-text-primary: #e8e8e8;
    --color-text-secondary: #9b9b9b;
    --color-text-tertiary: #808080;
    --color-text-bright: #f5f5f5;
    --color-accent: #a35705;
    --color-accent-hover: #b5660a;
    --color-accent-bg: rgba(163, 87, 5, 0.2);
    --color-delete: #ff6b6b;
    --color-disabled-text: #808080;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    padding: 24px 20px calc(100px + env(safe-area-inset-bottom));
    line-height: 1.5;
}

.container {
    max-width: 680px;
    margin: 0 auto;
}

.ingredient {
    background: var(--color-bg-secondary);
    padding: 24px;
    border-radius: 16px;
    margin-bottom: 16px;
    border: 1px solid transparent;
}

.ingredient-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 10px;
    line-height: 1;
}

.ingredient-header .btn-icon {
    margin-top: -2px;
}

.ingredient-number {
    font-weight: 400;
    color: var(--color-text-secondary);
    font-size: 14px;
    line-height: 1;
    user-select: none;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--color-accent);
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background 0.2s, color 0.2s;
    font-weight: 300;
    line-height: 1;
    user-select: none;
    flex-shrink: 0;
}

@media (hover: hover) {
    .btn-icon:hover {
        background: var(--color-accent-bg);
        color: var(--color-delete);
    }
}

.autocomplete-wrapper {
    position: relative;
}

.autocomplete-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    max-height: 240px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    display: none;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.autocomplete-list::-webkit-scrollbar {
    display: none;
}

.autocomplete-list.show {
    display: block;
}

.autocomplete-item {
    position: relative;
    padding: 16px;
    cursor: pointer;
    color: var(--color-text-primary);
    font-size: 15px;
    transition: background 0.15s;
    border-bottom: 1px solid var(--color-border-light);
    min-height: 52px;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.autocomplete-item:last-child {
    border-bottom: none;
    border-radius: 0 0 12px 12px;
}

.autocomplete-item:first-child {
    border-radius: 12px 12px 0 0;
}

.autocomplete-content {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

label {
    display: block;
    margin-bottom: 10px;
    font-size: 14px;
    color: var(--color-text-secondary);
    font-weight: 400;
    user-select: none;
}

input, textarea {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    font-size: 16px;
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    transition: border-color 0.2s, background 0.2s;
    -webkit-appearance: none;
    -moz-appearance: textfield;
}

input {
    margin-bottom: 16px;
}

textarea {
    margin-bottom: 10px;
    resize: none;
    min-height: 42px;
    max-height: 230px;
    font-family: inherit;
    line-height: 1.5;
    overflow-y: auto;
}

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

input:focus, textarea:focus {
    outline: none;
    border-color: var(--color-accent);
    background: #242424;
}

input::placeholder, textarea::placeholder {
    color: var(--color-text-tertiary);
}

.kbju-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 10px;
}

.kbju-grid input {
    margin-bottom: 0;
}

.kbju-labels {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 10px;
}

.kbju-labels label {
    margin-bottom: 0;
}

button {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    margin-top: 16px;
    transition: all 0.2s;
    user-select: none;
}

.add-btn {
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
}

.add-btn:disabled {
    background: var(--color-disabled-bg);
    color: var(--color-disabled-text);
    cursor: not-allowed;
    border-color: var(--color-disabled-bg);
}

.calculate-btn {
    background: transparent;
    color: var(--color-accent);
    border: 1px solid var(--color-accent);
    margin-top: 24px;
}

.calculate-btn:disabled {
    background: var(--color-disabled-bg);
    color: var(--color-disabled-text);
    border-color: var(--color-disabled-bg);
    cursor: not-allowed;
}

.draft-btn {
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
    font-size: 15px;
    padding: 14px;
    margin-top: 12px;
}

.draft-btn:disabled {
    background: var(--color-disabled-bg);
    color: var(--color-disabled-text);
    cursor: not-allowed;
    border-color: var(--color-disabled-bg);
}

.result {
    background: var(--color-bg-secondary);
    padding: 24px;
    border-radius: 16px;
    margin-top: 28px;
    display: none;
    border: 1px solid transparent;
}

.result.show {
    display: block;
}

.result h2 {
    font-size: 16px;
    margin-bottom: 20px;
    color: var(--color-text-primary);
    font-weight: 500;
    user-select: none;
    white-space: pre-line;
    word-wrap: break-word;
}

.result .kbju-grid input {
    background: var(--color-bg-primary);
    cursor: default;
    color: var(--color-text-primary);
    font-weight: 400;
    text-align: left;
    pointer-events: none;
    user-select: none;
}

.new-dish-btn {
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
    margin-top: 12px;
    border: 1px solid var(--color-border);
}

.draft-section {
    margin-top: 48px;
    margin-bottom: 24px;
}

.draft-item {
    background: var(--color-bg-secondary);
    padding: 12px 16px;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s;
    border: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
}

.draft-item .btn-icon {
    margin-top: -2px;
}

.draft-content {
    flex: 1;
    font-size: 14px;
    color: var(--color-text-tertiary);
}

.history {
    margin-top: 48px;
}

.history h2 {
    display: none;
}

.history-item {
    background: var(--color-bg-secondary);
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: background 0.2s;
    border: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
}

.history-item .btn-icon {
    margin-top: -2px;
}

.history-content {
    flex: 1;
}

.history-name {
    font-weight: 500;
    margin-bottom: 10px;
    color: var(--color-text-bright);
    font-size: 16px;
    white-space: pre-line;
    word-wrap: break-word;
}

.history-kbju {
    font-size: 14px;
    color: var(--color-text-secondary);
}

.history-recipe {
    font-size: 14px;
    color: var(--color-text-tertiary);
    font-style: italic;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--color-border);
}

.clear-history {
    background: #3d2d2d;
    color: var(--color-accent);
    font-size: 15px;
    padding: 14px;
    border: 1px solid #4d3d3d;
    transition: background 0.2s, color 0.2s;
}

@media (hover: hover) {
    .autocomplete-item:hover {
        background: var(--color-bg-hover);
    }
    
    .add-btn:hover {
        background: var(--color-bg-hover);
    }
    
    .calculate-btn:not(:disabled):hover {
        background: var(--color-accent-bg);
    }
    
    .draft-btn:not(:disabled):hover {
        background: var(--color-bg-hover);
    }
    
    .new-dish-btn:hover {
        background: var(--color-bg-hover);
    }
    
    .draft-item:hover {
        background: var(--color-bg-hover);
    }
    
    .history-item:hover {
        background: var(--color-bg-hover);
    }
    
    .clear-history:hover {
        background: #4d3d3d;
        color: var(--color-delete);
    }
}
