/* gym_log — built for one screen: an iPhone held in one hand, in a gym.
   Rules that drive everything below:
   - every tappable thing is >= 44px tall (Apple's touch target minimum);
   - inputs are >= 16px so iOS Safari never zooms on focus;
   - the layout respects the notch and the home indicator (safe-area insets);
   - only the editor and the history list scroll — the shell never moves. */

:root {
  --bg: #0d0f13;
  --bg-raised: #171a21;
  --bg-input: #1e222b;
  --line: #262b36;
  --text: #eef1f6;
  --muted: #8b93a3;
  --accent: #ff6a3d;
  --accent-dim: #3a2119;
  --ok: #2ecc71;
  --danger: #ff5c5c;
  --radius: 14px;
  --tabbar-h: 56px;
  --topbar-h: 52px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body { touch-action: manipulation; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }

.muted { color: var(--muted); }
.small { font-size: 14px; }
.error { color: var(--danger); }
[hidden] { display: none !important; }

/* ---------- login ---------- */

#view-login {
  display: none;
  min-height: 100dvh;
  padding: calc(var(--safe-top) + 24px) 22px calc(var(--safe-bottom) + 24px);
  align-items: center;
  justify-content: center;
}
#view-login.active { display: flex; }

.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-mark { font-size: 56px; line-height: 1; margin-bottom: 12px; }
.login-card h1 { font-size: 30px; margin-bottom: 10px; }
.login-card p { margin: 0 0 22px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }

/* ---------- shell ---------- */

#shell { display: flex; flex-direction: column; height: 100dvh; }

#topbar {
  flex: 0 0 auto;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) calc(16px + var(--safe-right)) 0 calc(16px + var(--safe-left));
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(13, 15, 19, 0.85);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
#topbar h1 { font-size: 20px; }
#topbar-right { display: flex; gap: 8px; align-items: center; }

#main {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 calc(16px + var(--safe-right)) 20px calc(16px + var(--safe-left));
}

.view { display: none; }
.view.active { display: block; }

.pane { padding-top: 16px; }

/* ---------- tab bar ---------- */

#tabs {
  flex: 0 0 auto;
  display: flex;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(13, 15, 19, 0.92);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  font-size: 11px;
  color: var(--muted);
  padding: 6px 0;
  transition: color 0.12s;
}
.tab span { font-size: 21px; line-height: 1; }
.tab.active { color: var(--accent); }
.tab:active { opacity: 0.6; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 46px; padding: 0 18px;
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--text);
  font-weight: 600;
  border: 1px solid var(--line);
  transition: transform 0.08s, opacity 0.12s;
}
.btn:active { transform: scale(0.975); opacity: 0.85; }
.btn.big { width: 100%; min-height: 54px; font-size: 18px; }
.btn.small { min-height: 38px; padding: 0 13px; font-size: 14px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #12100f; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #06210f; }
.btn.danger { background: transparent; border-color: #4a2a2a; color: var(--danger); }
.btn.ghost { background: transparent; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

/* ---------- inputs ---------- */

input, select, textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  font-size: 17px; /* >=16px: stops iOS zooming the page on focus */
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}
select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8'><path d='M1 1l5 5 5-5' stroke='%238b93a3' stroke-width='1.8' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 38px;
}

.field { display: block; margin: 14px 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field.inline { flex: 1; margin: 0; }

/* ---------- now / session ---------- */

.hero { text-align: center; padding: 26px 0 6px; }
.hero-mark { font-size: 52px; line-height: 1; margin-bottom: 10px; }
.hero p { margin: 4px 0; }

.session-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.range { font-size: 15px; color: var(--muted); }
.elapsed { font-size: 30px; font-weight: 680; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

.template-row { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 12px; }

.toolbar {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px;
  scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }
.tool {
  flex: 0 0 auto;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 14px;
  color: var(--text);
  min-height: 40px;
}
.tool:active { background: var(--accent-dim); }

#editor, #detail-editor {
  min-height: 46dvh;
  line-height: 1.55;
  resize: none;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 16px;
}

.rating-row { display: flex; align-items: center; gap: 12px; margin: 14px 0 6px; }
.stars { display: flex; gap: 4px; }
.star {
  font-size: 26px; line-height: 1; padding: 6px;
  filter: grayscale(1) opacity(0.35);
  transition: filter 0.12s, transform 0.08s;
}
.star.on { filter: none; }
.star:active { transform: scale(0.9); }

.save-row { display: flex; justify-content: space-between; gap: 10px; padding-bottom: 10px; }
#note-path, #detail-note-path { text-align: right; word-break: break-all; }

.danger-row { display: flex; gap: 10px; justify-content: space-between; margin-top: 18px; }

/* ---------- history ---------- */

.list { padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }

.item {
  display: block; width: 100%; text-align: left;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.item:active { background: #1d212a; }
.item .item-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.item .item-date { font-weight: 640; font-size: 17px; }
.item .item-dur { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.item .item-sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.item .item-preview {
  color: var(--muted); font-size: 14px; margin-top: 8px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.item .badge {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--accent); border: 1px solid var(--accent);
  border-radius: 6px; padding: 1px 6px; margin-left: 8px; vertical-align: 2px;
}

.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* ---------- settings ---------- */

.card {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 { font-size: 17px; margin-bottom: 8px; }
.card .btn { margin-top: 10px; margin-right: 8px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }

/* ---------- toast ---------- */

#toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  background: #23282f;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 16px;
  border-radius: 999px;
  font-size: 15px;
  z-index: 50;
  max-width: 88vw;
  text-align: center;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.5);
}
