/* === Design tokens === */

:root {
    --color-bg: #ffffff;
    --color-bg-alt: #f5f5f5;
    --color-text: #1a1a1a;
    --color-text-muted: #6b6b6b;
    --color-text-light: #999999;
    --color-border: #e5e5e5;
    --color-nav-bg: #1a1a1a;
    --color-nav-text: #ffffff;
    --color-nav-text-muted: #999999;
    --color-link: #1a1a1a;
    --color-link-hover: #000000;
    --color-tag-bg: #f0f0f0;
    --color-tag-text: #4a4a4a;
    --color-accent: #c96b3c;
    --color-accent-hover: #b55d32;
    --color-danger: #c0392b;

    --font-body: system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-weight-light: 300;
    --font-weight-regular: 400;
    --font-weight-medium: 500;

    --space-xs: 0.5rem;
    --space-sm: 1rem;
    --space-md: 2rem;
    --space-lg: 4rem;

    --max-content: 900px;
    --nav-height: 80px;
    --transition: 0.2s ease;
}

[data-theme="dark"] {
    --color-bg: #111111;
    --color-bg-alt: #1a1a1a;
    --color-text: #e5e5e5;
    --color-text-muted: #999999;
    --color-text-light: #666666;
    --color-border: #333333;
    --color-link: #e5e5e5;
    --color-link-hover: #ffffff;
    --color-tag-bg: #2a2a2a;
    --color-tag-text: #cccccc;
    --color-accent: #d4845c;
    --color-accent-hover: #e0956d;
}

/* === Reset === */

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

/* === Base === */

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-body);
    font-weight: var(--font-weight-regular);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--color-link);
    text-decoration: none;
    transition: color var(--transition);
}

a:hover {
    color: var(--color-link-hover);
}

/* === Navigation === */

.site-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--color-nav-bg);
    z-index: 100;
    transition: transform 0.3s ease;
    border-bottom: 3px solid var(--color-accent);
}

.nav-inner {
    max-width: var(--max-content);
    margin: 0 auto;
    padding: 0 var(--space-sm);
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-brand {
    color: var(--color-accent);
    font-weight: var(--font-weight-medium);
    font-size: 1.4rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.nav-brand:hover {
    color: var(--color-accent-hover);
}

.nav-links {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.nav-links a {
    color: var(--color-nav-text-muted);
    font-size: 1.05rem;
}

.nav-links a:hover {
    color: var(--color-nav-text);
}

.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--color-nav-text);
    font-size: 1.25rem;
    cursor: pointer;
    padding: var(--space-xs);
}

.nav-spacer {
    height: var(--nav-height);
}

.theme-toggle {
    background: none;
    border: none;
    color: var(--color-nav-text-muted);
    cursor: pointer;
    padding: var(--space-xs);
    font-size: 1rem;
    line-height: 1;
}

.nav-lock-btn {
    background: none;
    border: none;
    color: var(--color-nav-text-muted);
    cursor: pointer;
    padding: var(--space-xs);
    font-size: 1.1rem;
    line-height: 1;
}

.fontsize-toggle {
    background: none;
    border: none;
    color: var(--color-nav-text-muted);
    cursor: pointer;
    padding: var(--space-xs);
    line-height: 1;
    display: flex;
    align-items: baseline;
    gap: 1px;
}

.fs-small {
    font-size: 0.7rem;
}

.fs-large {
    font-size: 1.05rem;
}

[data-theme="light"] .theme-icon-dark,
[data-theme="dark"] .theme-icon-light {
    display: none;
}

[data-theme="light"] .theme-icon-light,
[data-theme="dark"] .theme-icon-dark {
    color: var(--color-nav-text-muted);
}

/* === Layout === */

.content-wrap {
    max-width: var(--max-content);
    margin: 0 auto;
    padding: 0 var(--space-sm);
    width: 100%;
    flex: 1;
}

.section {
    padding: var(--space-md) 0;
}

.section-narrow {
    max-width: 480px;
    margin: 0 auto;
    padding: var(--space-md) 0;
}

/* === Landing === */

.landing-hero {
    padding: var(--space-lg) 0 var(--space-sm);
}

.landing-hero h1 {
    font-weight: var(--font-weight-light);
    font-size: clamp(1.8rem, 4vw, 2.5rem);
    letter-spacing: -0.02em;
}

.subtitle {
    color: var(--color-accent);
    font-size: 0.95rem;
    margin-top: var(--space-xs);
}

/* === Search === */

.search-bar {
    margin-bottom: var(--space-md);
}

.search-input {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    font-family: var(--font-body);
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 0;
    -webkit-appearance: none;
    appearance: none;
    transition: border-color var(--transition);
}

.search-input:focus {
    outline: none;
    border-color: var(--color-accent);
}

/* === Tags === */

.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin-bottom: var(--space-md);
}

.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.35rem 0.75rem;
    background: var(--color-tag-bg);
    color: var(--color-tag-text);
    font-size: 0.825rem;
    border-radius: 2px;
    transition: background var(--transition);
}

.tag-chip:hover {
    background: var(--color-border);
    color: var(--color-text);
}

.tag-count {
    font-size: 0.75rem;
    color: var(--color-text-light);
}

/* === Recipe list === */

.recipe-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.recipe-card {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--color-border);
    transition: padding-left var(--transition);
}

.recipe-card:first-child {
    border-top: 1px solid var(--color-border);
}

.recipe-card:hover {
    padding-left: 0.75rem;
    border-left: 3px solid var(--color-accent);
}

.recipe-card h3 {
    font-weight: var(--font-weight-regular);
    font-size: 1rem;
}

.recipe-card-meta {
    color: var(--color-text-muted);
    font-size: 0.825rem;
    white-space: nowrap;
    margin-left: var(--space-sm);
}

.empty-state {
    color: var(--color-text-muted);
    padding: var(--space-md) 0;
}

/* === Recipe view === */

.recipe-header {
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-md);
}

.recipe-header h1 {
    font-weight: var(--font-weight-light);
    font-size: clamp(1.6rem, 4vw, 2.2rem);
    letter-spacing: -0.02em;
}

.recipe-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    margin-top: var(--space-xs);
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

.recipe-tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin-top: var(--space-sm);
}

.recipe-actions {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    margin-top: var(--space-sm);
}

.recipe-actions .wake-toggle {
    margin-left: auto;
}

.recipe-body {
    line-height: 1.8;
    font-size: 1.05rem;
}

.recipe-body h2 {
    font-weight: var(--font-weight-medium);
    font-size: 1.2rem;
    margin: var(--space-md) 0 var(--space-xs);
    letter-spacing: -0.01em;
}

.recipe-body h3 {
    font-weight: var(--font-weight-medium);
    font-size: 1.05rem;
    margin: var(--space-sm) 0 var(--space-xs);
}

.recipe-body p {
    margin-bottom: var(--space-sm);
}

.recipe-body ul, .recipe-body ol {
    margin: 0 0 var(--space-sm) var(--space-md);
}

.recipe-body li {
    margin-bottom: 0.35rem;
}

.recipe-body li label {
    cursor: pointer;
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.recipe-body li input[type="checkbox"] {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.recipe-body li input[type="checkbox"]:checked + span {
    text-decoration: line-through;
    color: var(--color-text-muted);
}

.recipe-body blockquote {
    border-left: 3px solid var(--color-border);
    padding-left: var(--space-sm);
    color: var(--color-text-muted);
    margin: var(--space-sm) 0;
}

.recipe-body code {
    background: var(--color-bg-alt);
    padding: 0.15em 0.4em;
    font-size: 0.9em;
}

.recipe-body pre {
    background: var(--color-bg-alt);
    padding: var(--space-sm);
    overflow-x: auto;
    margin: var(--space-sm) 0;
}

.recipe-body pre code {
    padding: 0;
    background: none;
}

.recipe-body hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: var(--space-md) 0;
}

/* === Wake lock toggle === */

.wake-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

.wake-toggle input {
    display: none;
}

.wake-slider {
    position: relative;
    width: 40px;
    height: 22px;
    background: var(--color-border);
    border-radius: 11px;
    transition: background var(--transition);
    flex-shrink: 0;
}

.wake-slider::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    background: var(--color-bg);
    border-radius: 50%;
    transition: transform var(--transition);
}

.wake-toggle input:checked + .wake-slider {
    background: #4a90d9;
}

.wake-toggle input:checked + .wake-slider::after {
    transform: translateX(18px);
}

.wake-label {
    font-size: 0.825rem;
    color: var(--color-text-muted);
}

/* === Forms === */

.recipe-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.recipe-form label {
    font-size: 0.8rem;
    font-weight: var(--font-weight-medium);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: var(--space-xs);
}

.recipe-form label:first-child {
    margin-top: 0;
}

.optional {
    font-weight: var(--font-weight-regular);
    text-transform: none;
    color: var(--color-text-muted);
    letter-spacing: normal;
}

.recipe-form input[type="text"],
.recipe-form input[type="password"],
.recipe-form input[type="search"],
.recipe-form textarea {
    width: 100%;
    padding: 0.65rem 0.75rem;
    font-size: 1rem;
    font-family: var(--font-body);
    color: var(--color-text);
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: 0;
    -webkit-appearance: none;
    appearance: none;
    transition: border-color var(--transition);
}

.recipe-form input:focus,
.recipe-form textarea:focus {
    outline: none;
    border-color: var(--color-text);
}

.recipe-form textarea {
    resize: vertical;
    line-height: 1.6;
    font-size: 0.95rem;
}

.form-row {
    display: flex;
    gap: var(--space-sm);
}

.form-row .form-field {
    flex: 1;
}

.form-row input[type="number"] {
    width: 100%;
    padding: 0.65rem 0.75rem;
    font-size: 1rem;
    font-family: var(--font-body);
    color: var(--color-text);
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: 0;
    -webkit-appearance: none;
    appearance: none;
    transition: border-color var(--transition);
}

.form-row input[type="number"]:focus {
    outline: none;
    border-color: var(--color-text);
}

.form-error {
    background: var(--color-danger);
    color: #ffffff;
    padding: 0.65rem 0.75rem;
    font-size: 0.9rem;
    margin-bottom: var(--space-xs);
}

/* === Buttons === */

.btn {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    font-size: 0.875rem;
    font-family: var(--font-body);
    font-weight: var(--font-weight-medium);
    text-align: center;
    border: 1px solid transparent;
    cursor: pointer;
    transition: opacity var(--transition);
    -webkit-appearance: none;
    appearance: none;
    border-radius: 0;
}

.btn:hover {
    opacity: 0.8;
}

.btn-primary {
    background: var(--color-text);
    color: var(--color-bg);
    margin-top: var(--space-sm);
}

.btn-secondary {
    background: transparent;
    color: var(--color-accent);
    border-color: var(--color-accent);
}

.btn-danger {
    background: transparent;
    color: var(--color-danger);
    border-color: var(--color-danger);
}

.delete-form {
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--color-border);
}

/* === Footer === */

.site-footer {
    margin-top: auto;
    border-top: 1px solid var(--color-border);
    padding: var(--space-md) 0;
}

.footer-inner {
    max-width: var(--max-content);
    margin: 0 auto;
    padding: 0 var(--space-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

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

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

.inline-form {
    display: inline;
}

.link-button {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font: inherit;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
}

.link-button:hover {
    color: var(--color-text);
}

/* === Font size toggle === */

[data-fontsize="large"] .recipe-body {
    font-size: 1.2rem;
}

[data-fontsize="large"] .recipe-body h2 {
    font-size: 1.4rem;
}

[data-fontsize="large"] .recipe-body h3 {
    font-size: 1.2rem;
}

[data-fontsize="large"] .recipe-header h1 {
    font-size: clamp(1.8rem, 4vw, 2.6rem);
}

[data-fontsize="large"] .recipe-card h3 {
    font-size: 1.1rem;
}

[data-fontsize="large"] .recipe-meta,
[data-fontsize="large"] .recipe-card-meta {
    font-size: 0.95rem;
}

[data-fontsize="large"] .subtitle {
    font-size: 1.05rem;
}

[data-fontsize="xlarge"] .recipe-body {
    font-size: 1.35rem;
    line-height: 1.9;
}

[data-fontsize="xlarge"] .recipe-body h2 {
    font-size: 1.6rem;
}

[data-fontsize="xlarge"] .recipe-body h3 {
    font-size: 1.35rem;
}

[data-fontsize="xlarge"] .recipe-header h1 {
    font-size: clamp(2rem, 5vw, 3rem);
}

[data-fontsize="xlarge"] .recipe-card h3 {
    font-size: 1.2rem;
}

[data-fontsize="xlarge"] .recipe-meta,
[data-fontsize="xlarge"] .recipe-card-meta {
    font-size: 1.05rem;
}

[data-fontsize="xlarge"] .subtitle {
    font-size: 1.15rem;
}

[data-fontsize="xlarge"] .search-input {
    font-size: 1.15rem;
    padding: 0.85rem 1rem;
}

/* === Responsive === */

@media (max-width: 720px) {
    .nav-toggle {
        display: block;
    }

    .nav-links {
        display: none;
        position: absolute;
        top: var(--nav-height);
        left: 0;
        right: 0;
        flex-direction: column;
        background: var(--color-nav-bg);
        padding: var(--space-sm);
        gap: var(--space-xs);
    }

    .nav-inner.open .nav-links {
        display: flex;
    }

    .footer-inner {
        flex-direction: column;
        gap: var(--space-xs);
        text-align: center;
    }

    .recipe-card {
        flex-direction: column;
        gap: 0.15rem;
    }

    .recipe-card-meta {
        margin-left: 0;
    }
}
