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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f2f3f7;
    color: #222;
    -webkit-tap-highlight-color: transparent;
}

.app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    background: #fff;
    display: flex;
    flex-direction: column;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    padding: 16px 20px;
}

.app-header h1 {
    font-size: 20px;
    font-weight: 700;
}

.app-header .sub {
    font-size: 13px;
    opacity: .85;
    margin-top: 2px;
}

.app-main {
    flex: 1;
    padding: 16px;
    padding-bottom: 90px;
}

/* Bottom tab bar */
.tab-bar {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    display: flex;
    background: #fff;
    border-top: 1px solid #e6e6ee;
    box-shadow: 0 -4px 16px rgba(0,0,0,.06);
    z-index: 20;
}

.tab-bar a {
    flex: 1;
    text-align: center;
    padding: 10px 0 calc(8px + env(safe-area-inset-bottom));
    text-decoration: none;
    color: #9a9aa8;
    font-size: 12px;
    font-weight: 600;
}

.tab-bar a .icon { display: block; font-size: 20px; margin-bottom: 2px; }

.tab-bar a.active { color: #667eea; }

/* Cards */
.card {
    background: #fff;
    border: 1px solid #ececf3;
    border-radius: 14px;
    padding: 16px;
    margin-bottom: 14px;
    box-shadow: 0 2px 8px rgba(20,20,50,.04);
}

.card h2 {
    font-size: 17px;
    margin-bottom: 4px;
}

.card .meta {
    font-size: 12px;
    color: #8a8a99;
    margin-bottom: 10px;
}

.exercise-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.exercise-icon {
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    background-image: url('/images/exercise_sprite.png?v=62');
    background-size: 560px 336px; /* 10cols×56 × 6rows×56 */
    background-repeat: no-repeat;
    border-radius: 10px;
}

.exercise-header-text {
    flex: 1;
    min-width: 0;
}

.exercise-name {
    font-weight: 700;
    font-size: 15px;
    margin-bottom: 2px;
}

.exercise-target {
    font-size: 12px;
    color: #8a8a99;
    font-weight: 400;
}

.set-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-top: 1px solid #f2f2f7;
}

.set-row:first-of-type { border-top: none; }

.set-label {
    width: 28px;
    font-size: 13px;
    font-weight: 700;
    color: #777;
}

.set-input {
    width: 100%;
    border: 1px solid #e1e1ea;
    border-radius: 8px;
    padding: 8px 6px;
    font-size: 14px;
    text-align: center;
}

.set-input:disabled {
    background: #f7f7fb;
    color: #555;
}

.set-input-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 4px;
}

.set-input-wrap .unit {
    font-size: 12px;
    color: #999;
    min-width: 22px;
    white-space: nowrap;
    flex-shrink: 0;
}

.set-check-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 2px solid #d8d8e6;
    background: #fff;
    color: #c4c4d4;
    font-size: 18px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
}

.set-check-btn.done {
    border-color: #4cae50;
    background: #4cae50;
    color: #fff;
}

/* Treadmill row: wrap inputs so 3 fields fit comfortably */
.set-row.treadmill-row {
    flex-wrap: wrap;
    gap: 6px 8px;
}

/* Swim row: keep stroke select and lap input readable */
.set-row.swim-row {
    flex-wrap: wrap;
    gap: 6px 8px;
}

.set-row.swim-row .swim-stroke {
    flex: 1 1 90px;
    min-width: 0;
}

.set-row.swim-row .set-input-wrap {
    flex: 1 1 110px;
    min-width: 0;
}

.set-row.swim-row .set-check-btn {
    margin-left: auto;
}

.set-row.treadmill-row .set-input-wrap {
    flex: 1 1 80px;
    min-width: 0;
}

.set-row.treadmill-row .set-check-btn {
    margin-left: auto;
}

.empty {
    text-align: center;
    color: #999;
    padding: 40px 10px;
    font-size: 14px;
}

.move-btns {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-shrink: 0;
}

.btn-move {
    width: 24px;
    height: 18px;
    border: 1px solid #e1e1ea;
    border-radius: 5px;
    background: #fff;
    color: #888;
    font-size: 8px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-move:disabled {
    opacity: 0.3;
    cursor: default;
}

button.chip-edit {
    border: none;
    cursor: pointer;
    font-family: inherit;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
}

.modal-overlay[hidden] { display: none; }

.modal-card {
    background: #fff;
    border-radius: 14px;
    padding: 18px;
    width: 100%;
    max-width: 340px;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-card h2 { font-size: 16px; }

.modal-card .field input,
.modal-card .field select {
    width: 100%;
    border: 1px solid #e1e1ea;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 15px;
}

.streak-pill {
    display: inline-block;
    background: #fff4e5;
    color: #c05621;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 7px;
    margin-left: 4px;
    vertical-align: middle;
}

.overload-pill {
    display: inline-block;
    background: #e8f6e9;
    color: #2f7d43;
    border: 1px solid #bfe3c4;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 8px;
    margin-left: 4px;
    vertical-align: middle;
}

/* Collapsible week cards on the plan tab */
details.week-card summary {
    cursor: pointer;
    list-style: none;
    user-select: none;
}

details.week-card summary::-webkit-details-marker { display: none; }

details.week-card summary::after {
    content: '▾';
    color: #b9b9c8;
    margin-left: auto;
    transition: transform 0.15s;
}

details.week-card[open] summary::after { transform: rotate(180deg); }

details.week-card:not([open]) summary { margin-bottom: 0; }

details.week-card form { margin-top: 10px; }

/* Forms */
.field {
    margin-bottom: 16px;
}

.field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #555;
    margin-bottom: 6px;
}

.field input {
    width: 100%;
    border: 1px solid #e1e1ea;
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 15px;
}

.field input[type="date"] {
    -webkit-appearance: none;
    appearance: none;
    display: block;
    min-height: 47px;
    background: #fff;
    color: inherit;
    font-family: inherit;
    text-align: left;
}

.field input[type="date"]::-webkit-date-and-time-value {
    text-align: left;
    line-height: normal;
}

.btn {
    display: block;
    width: 100%;
    padding: 14px;
    border-radius: 10px;
    border: none;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
}

.btn-outline {
    background: #fff;
    color: #667eea;
    border: 2px solid #667eea;
}

.error {
    color: #d23;
    font-size: 13px;
    margin-top: -10px;
    margin-bottom: 14px;
}

.alert-success {
    background: #e8f8ec;
    color: #2c8a3a;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 13px;
    margin-bottom: 14px;
}

.progress-bar {
    height: 8px;
    border-radius: 4px;
    background: #eee;
    overflow: hidden;
    margin: 6px 0 2px;
}

.progress-bar > div {
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    text-align: center;
}

.stat-grid .stat strong {
    display: block;
    font-size: 18px;
}

.stat-grid .stat span {
    font-size: 11px;
    color: #999;
}

.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-card {
    background: #fff;
    border-radius: 18px;
    padding: 36px 28px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
}

.login-card h1 {
    font-size: 24px;
    text-align: center;
    margin-bottom: 4px;
}

.login-card p.sub {
    text-align: center;
    color: #888;
    font-size: 13px;
    margin-bottom: 28px;
}

.inline-form-row {
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 6px 0;
}

select.set-input {
    background: #fff;
}

.flex-2 { flex: 2; }
.flex-shrink-0 { flex-shrink: 0; }

.btn-sm {
    display: inline-block;
    flex-shrink: 0;
    padding: 0 12px;
    height: 40px;
    border-radius: 8px;
    border: 2px solid #667eea;
    background: #fff;
    color: #667eea;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.btn-sm-danger {
    border-color: #e55353;
    color: #e55353;
}

.add-set-btn {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 9px 0;
    border-radius: 10px;
    border: 2px dashed #c3cbec;
    background: transparent;
    color: #667eea;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.add-set-btn:active {
    background: #eef1fd;
}

.set-adjust-row {
    display: flex;
    gap: 8px;
}

.set-adjust-row form {
    flex: 1;
}

.remove-set-btn {
    border-color: #e8cfcf;
    color: #c47a7a;
}

.remove-set-btn:active {
    background: #fdf0f0;
}

.routine-day-title {
    font-size: 15px;
    font-weight: 700;
    margin-top: 16px;
    margin-bottom: 4px;
}

.routine-day-title:first-child { margin-top: 0; }

.week-day-title {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.today-pill {
    background: #667eea;
    color: #fff;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 999px;
}

/* Exercise history chips (기록 탭) */
.history-exercise {
    padding: 10px 0;
    border-top: 1px solid #f2f2f7;
}

.history-exercise:first-of-type { border-top: none; padding-top: 0; }

.history-exercise-name {
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 6px;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chip {
    background: #f2f3f8;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 700;
    color: #555;
    white-space: nowrap;
}

/* 12-week check-in grid (체크 탭) */
.checkin-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 8px;
}

.checkin-grid .field-group label {
    display: block;
    font-size: 11px;
    color: #999;
    margin-bottom: 3px;
}

.memo-input {
    width: 100%;
    border: 1px solid #e1e1ea;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    margin-bottom: 8px;
}

.week-target {
    font-size: 12px;
    color: #8a8a99;
}

.week-diff {
    font-size: 12px;
    font-weight: 700;
}

.week-diff.down { color: #2c8a3a; }
.week-diff.up { color: #d23; }

/* Daily checklist (체크 탭) */
.checklist-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-top: 1px solid #f2f2f7;
}

.checklist-item:first-of-type { border-top: none; padding-top: 0; }

.checklist-item .check-circle {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid #d8d8e6;
    background: #fff;
    color: transparent;
    font-size: 14px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
}

.checklist-item .check-circle.done {
    border-color: #4cae50;
    background: #4cae50;
    color: #fff;
}

.checklist-item .label {
    flex: 1;
}

.checklist-item .label .title {
    font-size: 14px;
    font-weight: 600;
}

.checklist-item .label .hint {
    font-size: 11px;
    color: #999;
}

/* Static reference tables (보충제 가이드, 흔한 실수) */
.ref-item {
    padding: 10px 0;
    border-top: 1px solid #f2f2f7;
}

.ref-item:first-of-type { border-top: none; padding-top: 0; }

.ref-item .name {
    font-weight: 700;
    font-size: 14px;
}

.ref-item .timing {
    font-size: 12px;
    color: #667eea;
    font-weight: 600;
    margin-top: 2px;
}

.ref-item .note {
    font-size: 12px;
    color: #888;
    margin-top: 2px;
}

.mistake-list {
    font-size: 13px;
    color: #b33;
    line-height: 1.7;
}
