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

:root {
    --bg: #f2ede3;
    --paper: #faf7f0;
    --ink: #1c1917;
    --muted: #78716c;
    --border: #d6cfc2;
    --accent: #d97706;
    --accent-light: #fef3c7;
    --accent-green: #16a34a;
    --red: #dc2626;
    --tab-bg: #e8e2d6;
    --tab-active: #faf7f0;
    --rule: #e2dbd0;

    --mono: 'JetBrains Mono', monospace;
    --hand: 'Caveat', cursive;
    --serif: 'Lora', Georgia, serif;

    --radius: 4px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 6px 24px rgba(0,0,0,0.12);
}

html { scroll-behavior: smooth; }

body {
    font-family: var(--mono);
    background: var(--bg);
    color: var(--ink);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    transition: background 0.4s, color 0.4s;
}

/* Noise texture overlay */
.noise {
    pointer-events: none;
    position: fixed;
    inset: 0;
    z-index: 999;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 128px 128px;
}

/* ── HEADER ────────────────────────────────────── */
header {
    background: var(--ink);
    padding: 0 32px;
    height: 56px;
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    font-family: var(--mono);
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: -0.02em;
}

.logo-icon {
    color: var(--accent);
    font-size: 1.1rem;
}

.logo-accent {
    color: var(--accent);
}

.header-badge {
    font-family: var(--hand);
    font-size: 1rem;
    color: rgba(255,255,255,0.4);
    border: 1px solid rgba(255,255,255,0.15);
    padding: 2px 12px;
    border-radius: 20px;
}

/* ── TAB BAR ────────────────────────────────────── */
.tab-bar {
    background: var(--tab-bg);
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 56px;
    z-index: 90;
    overflow-x: auto;
    scrollbar-width: none;
}

.tab-bar::-webkit-scrollbar { display: none; }

.tab-bar-inner {
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0 24px;
    min-width: max-content;
}

.tab-group {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 8px 0;
}

.tab-group-label {
    font-family: var(--hand);
    font-size: 0.85rem;
    color: var(--muted);
    margin-right: 6px;
    padding-right: 6px;
    border-right: 1px solid var(--border);
    white-space: nowrap;
}

.tab-sep {
    width: 1px;
    height: 28px;
    background: var(--border);
    margin: 0 12px;
}

.tab {
    font-family: var(--mono);
    font-size: 0.72rem;
    font-weight: 500;
    padding: 6px 14px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius) var(--radius) 0 0;
    color: var(--muted);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    letter-spacing: 0.01em;
}

.tab:hover {
    color: var(--ink);
    background: rgba(255,255,255,0.5);
    border-color: var(--border);
}

.tab.active {
    background: var(--tab-active);
    border-color: var(--border);
    border-bottom-color: var(--tab-active);
    color: var(--accent);
    font-weight: 700;
    margin-bottom: -2px;
    padding-bottom: 8px;
}

/* ── MAIN ────────────────────────────────────── */
main {
    flex: 1;
    padding: 48px 56px;
    max-width: 760px;
    animation: fadeSlide 0.25s ease;
}

@keyframes fadeSlide {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── WELCOME ────────────────────────────────────── */
.welcome-screen {
    padding-top: 12px;
    position: relative;
}

.welcome-stamp {
    font-family: var(--hand);
    font-size: 0.85rem;
    letter-spacing: 0.25em;
    color: var(--accent);
    border: 2px solid var(--accent);
    display: inline-block;
    padding: 2px 12px;
    transform: rotate(-1.5deg);
    margin-bottom: 24px;
    opacity: 0.7;
}

.welcome-title {
    font-family: var(--serif);
    font-size: 3.8rem;
    font-weight: 600;
    line-height: 1.1;
    color: var(--ink);
    margin-bottom: 20px;
    letter-spacing: -0.03em;
}

.welcome-title em {
    font-style: italic;
    color: var(--accent);
}

.welcome-sub {
    font-family: var(--mono);
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 40px;
    line-height: 1.7;
    max-width: 480px;
}

.welcome-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    max-width: 480px;
}

.welcome-card {
    background: var(--paper);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    font-family: var(--hand);
    font-size: 1.1rem;
    color: var(--ink);
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: var(--shadow);
}

.card-num {
    font-family: var(--mono);
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--accent);
    display: block;
}

/* ── ACTIVITY HEADER ────────────────────────────── */
.activity-header {
    display: flex;
    align-items: baseline;
    gap: 16px;
    margin-bottom: 8px;
}

.activity-num {
    font-family: var(--hand);
    font-size: 0.9rem;
    color: var(--accent);
    border: 1.5px solid var(--accent);
    padding: 1px 10px;
    border-radius: 20px;
}

.activity-title {
    font-family: var(--serif);
    font-size: 2rem;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: -0.02em;
}

hr {
    border: none;
    border-top: 1.5px dashed var(--rule);
    margin-bottom: 28px;
    margin-top: 12px;
}

/* ── FORM ELEMENTS ───────────────────────────────── */
label {
    display: block;
    font-family: var(--hand);
    font-size: 1rem;
    color: var(--muted);
    margin-bottom: 4px;
}

input[type="text"],
input[type="number"] {
    display: block;
    width: 100%;
    max-width: 380px;
    padding: 10px 14px;
    background: var(--paper);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.88rem;
    font-family: var(--mono);
    color: var(--ink);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    margin-bottom: 16px;
}

input[type="text"]:focus,
input[type="number"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.1);
}

input[type="checkbox"] {
    width: 15px;
    height: 15px;
    accent-color: var(--accent);
    cursor: pointer;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--hand);
    font-size: 1rem;
    color: var(--ink);
    cursor: pointer;
    margin-bottom: 20px;
    text-transform: none;
    letter-spacing: 0;
}

/* ── BUTTONS ─────────────────────────────────────── */
.btn,
button:not(.tab):not(.delete-btn) {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 22px;
    background: var(--ink);
    color: var(--paper);
    border: none;
    border-radius: var(--radius);
    font-size: 0.8rem;
    font-family: var(--mono);
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.btn:hover,
button:not(.tab):not(.delete-btn):hover {
    background: #2c2825;
    transform: translateY(-1px);
}

.btn:active,
button:not(.tab):not(.delete-btn):active {
    transform: translateY(0);
}

/* ── RESULT CARD ─────────────────────────────────── */
.result-card {
    background: var(--paper);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
    padding: 20px 24px;
    margin-top: 20px;
    box-shadow: var(--shadow);
}

.result-card p {
    font-size: 0.85rem;
    color: var(--ink);
    margin-bottom: 8px;
    display: flex;
    gap: 12px;
    line-height: 1.5;
    font-family: var(--mono);
}

.result-card p:last-child { margin-bottom: 0; }

.result-key {
    font-family: var(--hand);
    font-size: 0.95rem;
    color: var(--muted);
    min-width: 90px;
}

/* ── LOOPS ───────────────────────────────────────── */
.loop-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 10px 0 20px;
}

.loop-item {
    background: var(--paper);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 7px 12px;
    font-family: var(--mono);
    font-size: 0.85rem;
    font-weight: 500;
    min-width: 40px;
    text-align: center;
    box-shadow: var(--shadow);
}

.loop-label {
    font-family: var(--hand);
    font-size: 1rem;
    color: var(--muted);
    margin-bottom: 8px;
    margin-top: 16px;
    display: block;
}

/* ── LISTS ───────────────────────────────────────── */
#list3, #list8 {
    list-style: none;
    margin: 16px 0 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 440px;
}

#list3 li, #list8 li {
    background: var(--paper);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    font-family: var(--mono);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
    animation: slideIn 0.2s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-6px); }
    to   { opacity: 1; transform: translateX(0); }
}

#list8 li span {
    cursor: pointer;
    flex: 1;
    transition: color 0.2s;
}

#list8 li span[style*="line-through"] {
    color: var(--muted);
}

.delete-btn {
    background: transparent !important;
    border: 1px solid var(--border) !important;
    color: var(--red) !important;
    padding: 3px 10px !important;
    font-size: 0.7rem !important;
    font-family: var(--mono) !important;
    font-weight: 600 !important;
    border-radius: var(--radius) !important;
    cursor: pointer !important;
    transform: none !important;
    text-transform: uppercase !important;
    letter-spacing: 0.04em !important;
    transition: background 0.15s !important;
}

.delete-btn:hover {
    background: #fff0f0 !important;
    border-color: var(--red) !important;
}

/* ── MISC ────────────────────────────────────────── */
#color-result, #dark-result {
    font-family: var(--hand);
    font-size: 1rem;
    color: var(--muted);
    margin-top: 14px;
}

.counter-display {
    margin-top: 12px;
    font-family: var(--mono);
    font-size: 2.4rem;
    font-weight: 700;
    color: var(--accent);
}

.counter-label {
    font-family: var(--hand);
    font-size: 1rem;
    color: var(--muted);
}

main p:not(.result-card p) {
    color: var(--muted);
    font-size: 0.85rem;
    line-height: 1.7;
    margin-top: 6px;
    font-family: var(--mono);
}

main h3:not(.loop-label) {
    font-family: var(--serif);
    font-size: 1rem;
    font-weight: 400;
    color: var(--ink);
    margin: 20px 0 6px;
}

/* ── FOOTER ──────────────────────────────────────── */
footer {
    background: var(--ink);
    color: rgba(255,255,255,0.35);
    padding: 16px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: var(--mono);
    font-size: 0.75rem;
}

.footer-line {
    color: var(--accent);
    opacity: 0.7;
    font-weight: 700;
}

/* ── DARK MODE ───────────────────────────────────── */
body.dark-mode {
    --bg: #141210;
    --paper: #1c1915;
    --border: #2d2a24;
    --ink: #f0ebe0;
    --muted: #7a7060;
    --rule: #2a2620;
    --tab-bg: #111009;
    --tab-active: #1c1915;
}

body.dark-mode header { background: #0a0905; }
body.dark-mode footer { background: #0a0905; }

body.dark-mode input[type="text"],
body.dark-mode input[type="number"] {
    background: var(--paper);
    border-color: var(--border);
    color: var(--ink);
}

body.dark-mode .result-card,
body.dark-mode .loop-item,
body.dark-mode .welcome-card,
body.dark-mode #list3 li,
body.dark-mode #list8 li {
    background: var(--paper);
    border-color: var(--border);
}

body.dark-mode button:not(.tab):not(.delete-btn) {
    background: var(--accent);
    color: #111;
}

body.dark-mode button:not(.tab):not(.delete-btn):hover {
    background: #e08010;
}

/* ── SCROLLBAR ───────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
body.dark-mode ::-webkit-scrollbar-thumb { background: #333; }
