:root {
  --bg: #f3f4f8;
  --card: #ffffff;
  --card2: #f0f2f6;
  --accent: #2563eb;
  --green: #16a34a;
  --warn: #d97706;
  --red: #dc2626;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --radius: 14px;
}

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

html,
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  max-width: 100%;
  overflow-x: hidden;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body {
  padding-bottom: 0;
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

input,
select,
textarea {
  font-size: 16px;
}

.boot-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.boot-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
  width: min(420px, 100%);
}

header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px 0;
  position: sticky;
  top: 0;
  z-index: 30;
}

.hdr-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

h1 {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.app-title {
  cursor: pointer;
}

.debug-version {
  display: inline-block;
  margin-left: 6px;
  font-size: 0.72em;
  font-weight: 700;
  color: var(--accent);
  vertical-align: middle;
}

.hdr-sub {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.45;
}

.hdr-state {
  font-size: 0.73rem;
  margin-top: 4px;
}

.hdr-state.ok {
  color: var(--green);
}

.hdr-state.dirty,
.hdr-state.saving {
  color: var(--warn);
}

.hdr-state.error {
  color: var(--red);
}

.hdr-params {
  font-size: 0.7rem;
  color: var(--muted);
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  max-width: 190px;
  line-height: 1.45;
  text-align: right;
}

.tabs {
  display: flex;
  gap: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  padding: 8px 14px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: all 0.15s;
  flex-shrink: 0;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab.today .tab-bullet {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  margin-left: 4px;
  vertical-align: middle;
}

.tab-bullet {
  display: none;
}

.main {
  --main-height: 60vh;
  height: var(--main-height);
  padding: 14px 14px 0;
  max-width: 720px;
  margin: 0 auto;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-snap-type: y mandatory;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}

.day-banner {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.5;
}

.day-banner strong {
  color: var(--text);
}

.day-note {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.76rem;
  color: #92400e;
  line-height: 1.5;
  margin-bottom: 14px;
}

.ex-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
  scroll-margin-top: 126px;
}

.exercise-page {
  min-height: var(--main-height);
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding-bottom: 14px;
}

.ex-card.current {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
}

.ex-card.all-done {
  border-color: #86efac;
}

.ex-hdr {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  user-select: none;
}

.ex-aside {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  width: 72px;
}

.ex-num {
  width: 44px;
  height: 30px;
  border-radius: 8px;
  background: var(--card2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--muted);
}

.ex-num.done {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.ex-thumb {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: zoom-in;
}

.btn-ghid {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  font-size: 1rem;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 38px;
}

.btn-ghid.disabled {
  opacity: 0.35;
}

.ex-body {
  flex: 1;
  min-width: 0;
}

.ex-name {
  font-weight: 700;
  font-size: 0.93rem;
  line-height: 1.3;
}

.ex-name-en {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 1px;
}

.ex-tags {
  display: flex;
  gap: 6px;
  margin-top: 5px;
  flex-wrap: wrap;
}

.tag {
  font-size: 0.68rem;
  padding: 2px 7px;
  border-radius: 4px;
  font-weight: 600;
}

.tag-btn {
  border: none;
  cursor: pointer;
}

.tag-green {
  background: rgba(86, 212, 154, 0.12);
  color: var(--green);
}

.tag-warn {
  background: rgba(247, 162, 79, 0.12);
  color: var(--warn);
}

.tag-blue {
  background: rgba(79, 142, 247, 0.12);
  color: var(--accent);
}

.ex-progress {
  font-size: 0.75rem;
  margin-top: 4px;
}

.prog-done {
  color: var(--green);
}

.prog-partial {
  color: var(--warn);
}

.prog-none {
  color: var(--muted);
}

.setup-wrap {
  overflow: hidden;
  transition: max-height 0.25s ease;
  max-height: 220px;
}

.setup-wrap.collapsed {
  max-height: 0;
}

.setup-inner {
  padding: 0 14px 10px;
}

.setup-box {
  background: var(--card2);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.6;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 0 14px;
}

.series {
  padding: 4px 0 8px;
}

.serie {
  border-top: 1px solid var(--border);
  transition: background 0.2s;
}

.serie.done {
  background: #f0fdf4;
}

.serie-plan {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px;
  background: var(--card2);
  font-size: 0.75rem;
  color: var(--muted);
  flex-wrap: wrap;
}

.s-lbl {
  font-weight: 700;
  color: var(--text);
  opacity: 0.55;
  margin-right: 2px;
}

.serie-real {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 34px 34px;
  align-items: center;
  padding: 7px 14px;
  gap: 8px;
}

.ctrl-grp {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.bw-only {
  justify-content: center;
}

.bw-label {
  font-size: 0.75rem;
  color: var(--green);
  font-weight: 600;
}

.ctrl-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  background: var(--card2);
  color: var(--text);
  border-radius: 7px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ctrl-select {
  font-size: 0.97rem;
  font-weight: 800;
  min-width: 0;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--card2);
  color: var(--text);
  padding: 4px 2px 4px 6px;
  text-align: center;
  appearance: auto;
  -webkit-appearance: menulist;
}

.ctrl-val {
  font-size: 0.97rem;
  font-weight: 800;
  min-width: 38px;
  text-align: center;
}

.note-btn,
.done-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  flex-shrink: 0;
  cursor: pointer;
}

.note-btn {
  border: 1px solid var(--border);
  background: transparent;
}

.note-btn.has-note {
  border-color: var(--accent);
  background: rgba(37, 99, 235, 0.1);
}

.done-btn {
  border: 2px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
}

.done-btn.on {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  font-weight: 900;
}

.footer {
  position: sticky;
  bottom: 0;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: center;
  z-index: 30;
  max-width: 720px;
  margin: 0 auto;
}

.btn-export,
.btn-export-all,
.btn-reset {
  border-radius: 10px;
  padding: 11px 14px;
  cursor: pointer;
}

.btn-export {
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 0.88rem;
  font-weight: 800;
}

.btn-export-all {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
}

.btn-reset {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  font-size: 0.82rem;
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 60;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-overlay.open {
  display: flex;
}

.image-modal img {
  max-width: 92vw;
  max-height: 88vh;
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.modal-card {
  width: min(620px, 100%);
  background: var(--card);
  border-radius: 14px;
  padding: 16px;
}

.modal-card h2 {
  margin-bottom: 6px;
  font-size: 1rem;
}

.modal-card p {
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 12px;
}

.modal-list {
  display: grid;
  gap: 10px;
}

.modal-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.modal-card label {
  display: grid;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--muted);
}

.modal-card input,
.modal-card select,
.modal-card textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  color: var(--text);
  background: #fff;
}

.checkbox-row {
  display: flex !important;
  align-items: center;
  gap: 8px;
}

.checkbox-row input {
  width: auto;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 14px;
}

@media (max-width: 480px) {
  h1 {
    font-size: 1.25rem;
  }

  .hdr-sub {
    font-size: 0.85rem;
  }

  .hdr-state {
    font-size: 0.8rem;
  }

  .hdr-params {
    font-size: 0.78rem;
    max-width: 160px;
  }

  .tab {
    font-size: 0.9rem;
    padding: 9px 16px;
  }

  .day-banner,
  .day-note {
    font-size: 0.9rem;
  }

  .ex-card {
    scroll-margin-top: 152px;
  }

  .ex-name {
    font-size: 1.05rem;
  }

  .ex-name-en {
    font-size: 0.8rem;
  }

  .tag,
  .ex-progress,
  .setup-box,
  .serie-plan {
    font-size: 0.84rem;
  }

  .serie-real {
    padding: 6px 10px;
    gap: 5px;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 42px 42px;
  }

  .ctrl-btn,
  .note-btn,
  .done-btn {
    width: 42px;
    height: 42px;
  }

  .ctrl-select {
    font-size: 16px;
    min-width: 0;
    min-height: 42px;
  }

  .ctrl-btn,
  .note-btn,
  .done-btn,
  .btn-reset,
  .btn-export,
  .btn-export-all,
  .tag-btn {
    touch-action: manipulation;
  }

  .ctrl-val {
    font-size: 1.12rem;
    min-width: 40px;
  }

  .footer {
    gap: 6px;
  }
}
