:root {
    --bg: #efe7d6;
    --bg-2: #e8dec8;
    --card: #fffdf7;
    --ink: #2c2a25;
    --muted: #a09a8a;
    --line: #e7dec9;
    --accent: #9c6b3f;
    --radius: 18px;
    --shadow: 0 2px 6px rgba(60, 48, 28, .06), 0 22px 50px rgba(60, 48, 28, .14);
    --shadow-soft: 0 1px 3px rgba(60, 48, 28, .05), 0 10px 24px rgba(60, 48, 28, .08);
    --card-w: min(360px, 86vw);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    min-height: 100vh;
    background: radial-gradient(120% 90% at 50% 0%, var(--bg) 0%, var(--bg-2) 100%) fixed;
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

.wrap {
    max-width: 1180px;
    margin: 0 auto;
    padding: 40px 24px 0;
}

/* ---------- Header (fixed text, not editable) ---------- */
.site-head { text-align: center; }

.site-head h1 {
    margin: 0;
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.subtitle {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 1.05rem;
}

/* ---------- Structure reference ---------- */
.structure {
    position: relative;
    max-width: 700px;
    margin: 22px auto 0;
    text-align: center;
}

.structure-label {
    display: block;
    font-size: .66rem;
    font-weight: 700;
    letter-spacing: .15em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 10px;
}

.structure-view {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.chip {
    font-size: .82rem;
    color: var(--ink);
    background: rgba(255, 253, 247, .7);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 5px 13px;
}

.structure .edit { max-width: 420px; margin: 0 auto; text-align: left; }

/* ---------- Stage / coverflow ---------- */
.stage-wrap {
    position: relative;
    width: 100%;
    overflow: hidden;
    padding: 40px 0 18px;
}

.stage {
    position: relative;
    width: 100%;
    min-height: 240px;
    transition: height .45s cubic-bezier(.22, .61, .36, 1);
}

.day {
    position: absolute;
    top: 50%;
    left: 50%;
    width: var(--card-w);
    transform: translate(-50%, -50%);
    transform-origin: center center;
    will-change: transform, opacity, filter;
    transition: transform .5s cubic-bezier(.22, .61, .36, 1),
                opacity .5s ease,
                filter .5s ease;
}

.day-body {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 26px 26px;
    box-shadow: var(--shadow-soft);
}

.day.active .day-body { box-shadow: var(--shadow); }

/* Inactive cards: click anywhere to bring into focus */
.day:not(.active) { cursor: pointer; }
.day:not(.active) .day-body { pointer-events: none; user-select: none; }

.day-head { margin-bottom: 18px; }

.day-name {
    display: inline-block;
    font-size: .74rem;
    font-weight: 700;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--accent);
}

.day.is-today .day-name::after {
    content: " · today";
    color: var(--muted);
    font-weight: 500;
}

.day-title {
    margin: 6px 0 0;
    font-size: 1.45rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.block { margin-top: 22px; }

.block h3 {
    margin: 0 0 8px;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--muted);
}

.block ul { margin: 0; padding: 0; list-style: none; }

.block li {
    position: relative;
    padding-left: 18px;
    margin: 5px 0;
    font-size: 1rem;
}

.block li::before {
    content: "";
    position: absolute;
    left: 3px;
    top: .65em;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--accent);
    opacity: .6;
}

.empty { color: #cfc6b2; }

/* ---------- Pencil edit buttons ---------- */
.edit-pencil {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 120;
    display: none;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(255, 253, 247, .92);
    color: var(--muted);
    cursor: pointer;
    box-shadow: var(--shadow-soft);
    transition: color .15s ease, border-color .15s ease, transform .05s ease;
}
.edit-pencil:hover { color: var(--accent); border-color: var(--accent); }
.edit-pencil:active { transform: scale(.94); }

.day.active .edit-pencil { display: flex; }

.structure .edit-pencil { display: flex; top: 0; right: 0; width: 30px; height: 30px; }

body.editing .edit-pencil { display: none; }

/* ---------- Nav chevrons ---------- */
.nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 200;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: rgba(255, 253, 247, .85);
    backdrop-filter: blur(6px);
    color: var(--ink);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: var(--shadow-soft);
    transition: transform .1s ease, background .15s ease, opacity .2s ease;
}
.nav:hover { background: #fff; }
.nav:active { transform: translateY(-50%) scale(.94); }
/* Sit just outside the edges of the focused (centered) card */
.nav-prev { left: calc(50% - var(--card-w) / 2 - 58px); }
.nav-next { left: calc(50% + var(--card-w) / 2 + 12px); right: auto; }

/* ---------- Dots ---------- */
.dots {
    display: flex;
    justify-content: center;
    gap: 10px;
    padding: 14px 0 22px;
}

.dot {
    width: 9px;
    height: 9px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: #cdc3ab;
    cursor: pointer;
    transition: transform .2s ease, background .2s ease;
}
.dot:hover { background: var(--accent); opacity: .6; }
.dot.on { background: var(--accent); transform: scale(1.35); }

/* ---------- Editing (scoped per region) ---------- */
.edit { display: none; }

.day.editing .view,
.structure.editing .view { display: none; }

.day.editing .edit,
.structure.editing .edit { display: block; }

/* Hide empty title / empty blocks only when NOT editing that card */
.day:not(.editing) .day-title.hide-empty { display: none; }
.day:not(.editing) .block.is-empty { display: none; }

input.edit, textarea.edit {
    width: 100%;
    font-family: inherit;
    color: var(--ink);
    background: #fffaf0;
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 9px 11px;
    margin-top: 4px;
}
input.edit:focus, textarea.edit:focus {
    outline: none;
    border-color: var(--accent);
    background: #fff;
}
textarea.edit { resize: vertical; line-height: 1.5; font-size: .95rem; }

.day-title-input { font-size: 1.2rem; font-weight: 600; }

/* While editing, lock navigation so focus stays on the open card */
body.editing .nav,
body.editing .dots { opacity: .3; pointer-events: none; }

/* ---------- Buttons ---------- */
.btn {
    font: inherit;
    font-weight: 600;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--ink);
    border-radius: 10px;
    padding: 9px 18px;
    cursor: pointer;
    transition: background .12s ease, border-color .12s ease, transform .05s ease;
}
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { filter: brightness(1.12); }
.btn-primary:disabled { opacity: .6; cursor: default; }

.btn-ghost:hover { background: #f1e9d7; }

/* ---------- Save bar ---------- */
.save-bar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    display: none;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 14px 24px;
    background: rgba(255, 253, 247, .92);
    backdrop-filter: saturate(180%) blur(8px);
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 22px rgba(60, 48, 28, .08);
    z-index: 300;
}
body.editing .save-bar { display: flex; }

.save-hint { margin-right: auto; color: var(--muted); font-size: .9rem; }

.pin-input {
    font: inherit;
    width: 120px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 9px 12px;
    background: #fffaf0;
}
.pin-input:focus { outline: none; border-color: var(--accent); }

@media (max-width: 560px) {
    .wrap { padding: 28px 16px 0; }
    .site-head h1 { font-size: 1.6rem; }
    .nav { width: 40px; height: 40px; font-size: 1.4rem; }
    .nav-prev { left: 6px; }
    .nav-next { left: auto; right: 6px; }
    .save-hint { display: none; }
}

/* ---------- Bottom action (circular scale button) ---------- */
.bottom-actions {
    display: flex;
    justify-content: center;
    padding: 4px 0 64px;
}

.fab {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--ink);
    border: 1px solid var(--ink);
    color: #fff;
    text-decoration: none;
    box-shadow: var(--shadow);
    transition: transform .12s ease, filter .12s ease;
}
.fab:hover { filter: brightness(1.18); transform: translateY(-2px); }
.fab:active { transform: translateY(0); }

/* ---------- Weight page ---------- */
.back-link {
    display: inline-block;
    margin-bottom: 12px;
    color: var(--muted);
    text-decoration: none;
    font-size: .92rem;
    font-weight: 600;
}
.back-link:hover { color: var(--accent); }

.weight-card {
    max-width: 760px;
    margin: 26px auto 80px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 26px;
    box-shadow: var(--shadow-soft);
}

.weight-inputs {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 10px;
    margin-bottom: 26px;
}

.w-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.w-day {
    font-size: .66rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--accent);
    white-space: nowrap;
}

.w-input {
    width: 100%;
    text-align: center;
    font: inherit;
    font-size: 1rem;
    padding: 10px 4px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fffaf0;
    color: var(--ink);
}
.w-input:focus { outline: none; border-color: var(--accent); background: #fff; }

.w-cell.today .w-input { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(156, 107, 63, .15); }

.w-cell.future { opacity: .45; }
.w-cell.future .w-day { color: var(--muted); }
.w-cell.future .w-input { background: #ece5d4; cursor: not-allowed; }

.chart-wrap { width: 100%; }
.chart { width: 100%; height: auto; display: block; }
.chart text { font-family: inherit; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .y-label, .chart .x-label { fill: var(--muted); font-size: 12px; }
.chart .x-label.dim { fill: #cfc6b2; }
.chart .empty-msg { fill: var(--muted); font-size: 14px; }
.chart .avg-line { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 5; opacity: .7; }
.chart .data-line { stroke: var(--accent); stroke-width: 2.5; fill: none; stroke-linejoin: round; stroke-linecap: round; }
.chart .data-dot { fill: var(--accent); }

/* ---------- Weight tabs + week label + history ---------- */
.tabs {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 8px;
}
.tab {
    font: inherit;
    font-weight: 600;
    color: var(--muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 8px 20px;
    cursor: pointer;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.tab:hover { color: var(--ink); }
.tab.is-active {
    background: var(--card);
    color: var(--ink);
    border-color: var(--line);
    box-shadow: var(--shadow-soft);
}
.panel.is-hidden { display: none; }

.week-label {
    text-align: center;
    color: var(--muted);
    font-size: .85rem;
    font-weight: 600;
    letter-spacing: .03em;
    margin-bottom: 18px;
}

.weeks-list {
    margin-top: 22px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.week-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fffaf0;
}
.week-row.current { border-color: var(--accent); }
.week-row-main { display: flex; flex-direction: column; }
.week-row-num { font-weight: 700; font-size: .95rem; }
.week-row-date { color: var(--muted); font-size: .78rem; }
.week-row-val { font-weight: 700; font-size: 1rem; white-space: nowrap; }
.week-row-delta { font-size: .82rem; font-weight: 700; margin-left: 4px; }
.week-row-delta.pos { color: #3f7d4f; }
.week-row-delta.neg { color: #b4533b; }
.week-row-count { color: var(--muted); font-weight: 500; font-size: .78rem; margin-left: 6px; }
.weeks-empty { color: var(--muted); text-align: center; font-size: .9rem; padding: 16px 8px; line-height: 1.5; }

.weight-stats {
    display: flex;
    gap: 14px;
    margin-top: 24px;
}
.stat {
    flex: 1;
    text-align: center;
    background: #fffaf0;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px 10px;
}
.stat-label {
    display: block;
    font-size: .64rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 5px;
}
.stat-value { font-size: 1.3rem; font-weight: 700; }
.stat-value.pos { color: #3f7d4f; }
.stat-value.neg { color: #b4533b; }

.save-status {
    text-align: center;
    color: var(--muted);
    font-size: .85rem;
    min-height: 1.2em;
    margin: 14px 0 0;
}

@media (max-width: 560px) {
    .weight-card { padding: 20px 16px; margin-bottom: 60px; }
    .weight-inputs { grid-template-columns: 1fr; gap: 8px; }
    .w-cell { flex-direction: row; justify-content: space-between; }
    .w-input { width: 130px; }
    .weight-stats { flex-direction: column; }
}

/* ---------- Uniform cards: equal height, flush content ---------- */
.day-body { display: flex; flex-direction: column; }
/* min-height is set per-card in JS to the tallest card so days never resize */

/* Active card invites a tap to open the in-depth view */
.day.active:not(.editing) .day-body { cursor: pointer; }
.detail-hint {
    margin-top: auto;
    padding-top: 16px;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--muted);
    opacity: .8;
    display: flex;
    align-items: center;
    gap: 6px;
}
/* Keep the hint's space reserved on every card so heights stay uniform */
.day:not(.active) .detail-hint { visibility: hidden; }
.day.editing .detail-hint { display: none; }

/* ---------- Detail overlay ---------- */
.detail-overlay {
    position: fixed;
    inset: 0;
    z-index: 400;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.detail-overlay[hidden] { display: none; }
.detail-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(44, 36, 22, .42);
    backdrop-filter: blur(3px);
    animation: fadeIn .2s ease;
}
.detail-sheet {
    position: relative;
    width: min(440px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 28px 26px 26px;
    box-shadow: var(--shadow);
    animation: sheetIn .26s cubic-bezier(.22, .61, .36, 1);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetIn {
    from { opacity: 0; transform: translateY(14px) scale(.98); }
    to { opacity: 1; transform: none; }
}
body.detail-open { overflow: hidden; }

.detail-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(255, 253, 247, .92);
    color: var(--muted);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    transition: color .15s ease, border-color .15s ease;
}
.detail-close:hover { color: var(--accent); border-color: var(--accent); }

.detail-head { text-align: center; margin-bottom: 20px; }
.detail-title { margin: 6px 0 0; font-size: 1.5rem; font-weight: 600; letter-spacing: -.01em; }
.detail-structure {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    margin-top: 12px;
}

.detail-list { list-style: none; margin: 0 0 14px; padding: 0; }
.detail-ex {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 4px;
    border-bottom: 1px solid var(--line);
}
.detail-ex:last-child { border-bottom: none; }
.detail-ex-name { font-size: 1.02rem; font-weight: 500; }
.detail-ex-weight {
    flex: none;
    font-weight: 700;
    font-size: .95rem;
    color: var(--accent);
    background: rgba(156, 107, 63, .1);
    border-radius: 999px;
    padding: 4px 12px;
    white-space: nowrap;
}
.detail-ex-weight.is-num { font-size: 1.05rem; }

/* Editable weight pill */
.detail-ex-weight-input {
    width: 124px;
    text-align: center;
    font-family: inherit;
    border: 1px solid transparent;
    cursor: text;
    transition: border-color .12s ease, background .12s ease;
}
.detail-ex-weight-input:hover { border-color: rgba(156, 107, 63, .35); }
.detail-ex-weight-input:focus {
    outline: none;
    border-color: var(--accent);
    background: #fff;
}

.detail-status {
    text-align: center;
    color: var(--muted);
    font-size: .82rem;
    min-height: 1.1em;
    margin: -12px 0 18px;
}

/* ---------- Circular rest timer ---------- */
.rest-timer {
    border-top: 1px solid var(--line);
    padding-top: 22px;
    text-align: center;
}
.rest-label {
    display: block;
    font-size: .66rem;
    font-weight: 700;
    letter-spacing: .15em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 16px;
}
.ring-wrap {
    position: relative;
    width: 200px;
    height: 200px;
    margin: 0 auto;
}
.ring { width: 200px; height: 200px; display: block; }
.ring-track { fill: none; stroke: var(--line); stroke-width: 7; }
.ring-progress {
    fill: none;
    stroke: var(--accent);
    stroke-width: 7;
    stroke-linecap: round;
    transform: rotate(-90deg);
    transform-origin: 60px 60px;
}
.ring-progress.done { stroke: #3f7d4f; }

.ring-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
}
.rest-input {
    width: 96px;
    text-align: center;
    font: inherit;
    font-size: 2.6rem;
    font-weight: 700;
    line-height: 1;
    color: var(--ink);
    border: none;
    background: transparent;
    padding: 0;
}
.rest-input::-webkit-outer-spin-button,
.rest-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.rest-input { -moz-appearance: textfield; }
.rest-input:focus { outline: none; color: var(--accent); }
.rest-count { font-size: 2.9rem; font-weight: 700; line-height: 1; }
.rest-unit { font-size: .7rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }

.rest-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 20px;
}
.rest-step {
    font: inherit;
    font-weight: 700;
    color: var(--ink);
    background: #fffaf0;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 14px;
    min-width: 56px;
    cursor: pointer;
    transition: border-color .12s ease, background .12s ease, opacity .12s ease;
}
.rest-step:hover { border-color: var(--accent); }
.rest-step:disabled { opacity: .4; cursor: default; }
.rest-start { min-width: 110px; }
.rest-reset {
    margin-top: 12px;
    font: inherit;
    font-weight: 600;
    color: var(--muted);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
}
.rest-reset:hover { color: var(--accent); }

@media (max-width: 560px) {
    .detail-sheet { padding: 24px 18px 22px; border-radius: 20px; }
}
