/* ========== Reset & Base ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #0a0a0a;
  --bg-elev: #141414;
  --bg-card: #1a1a1a;
  --border: #2a2a2a;
  --text: #f5f5f5;
  --text-dim: #888;
  --text-faint: #555;
  --accent: #ff5722;
  --accent-soft: rgba(255, 87, 34, 0.15);
  --success: #10b981;
  --warn: #f59e0b;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --font: -apple-system, BlinkMacSystemFont, "Pretendard", "Noto Sans KR", "Segoe UI", system-ui, sans-serif;
  --mono: "SF Mono", "Monaco", "Consolas", monospace;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ========== Layout ========== */
.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

.header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  padding-top: calc(18px + env(safe-area-inset-top));
  background: rgba(10, 10, 10, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

.header__title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.header__title span {
  color: var(--accent);
  font-weight: 500;
  margin-left: 2px;
}

.header__sub {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.header__right {
  display: flex;
  gap: 6px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text-dim);
  transition: all 0.15s;
}

.icon-btn:hover, .icon-btn:active {
  background: var(--bg-elev);
  color: var(--text);
}

.main {
  padding: 16px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ========== Card ========== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.card__head h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

/* ========== Timer ========== */
.timer-card {
  background: linear-gradient(135deg, var(--bg-card) 0%, #1f1410 100%);
  border-color: rgba(255, 87, 34, 0.2);
}

.timer-mode {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 4px 10px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 12px;
}

.timer-display {
  font-family: var(--mono);
  font-size: 64px;
  font-weight: 700;
  text-align: center;
  margin: 12px 0 4px;
  letter-spacing: -2px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.timer-display.running {
  color: var(--accent);
}

.timer-display.warning {
  color: var(--warn);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.timer-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 16px;
  font-family: var(--mono);
}

.timer-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.timer-controls .btn {
  flex: 1;
}

.timer-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  padding: 6px 12px;
  font-size: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text-dim);
  transition: all 0.15s;
}

.chip:hover, .chip:active, .chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* ========== Summary ========== */
.summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 12px;
  background: var(--bg-elev);
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
}

.summary__item {
  text-align: center;
}

.summary__num {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--mono);
}

.summary__label {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ========== Exercise List ========== */
.exercise-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.exercise-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-elev);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
}

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

.exercise-item__name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.exercise-item__meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
  font-family: var(--mono);
}

.exercise-item__note {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 2px;
  font-style: italic;
}

.exercise-item__del {
  color: var(--text-faint);
  font-size: 18px;
  padding: 4px 8px;
}

.exercise-item__del:hover {
  color: var(--accent);
}

/* ========== WOD List ========== */
.wod-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.wod-item {
  padding: 12px;
  background: var(--bg-elev);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--success);
}

.wod-item__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.wod-item__name {
  font-weight: 600;
  font-size: 14px;
}

.wod-item__time {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--success);
  font-weight: 600;
}

.wod-item__content {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.4;
}

.wod-item__rpe {
  display: inline-block;
  font-size: 10px;
  padding: 2px 6px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 8px;
  margin-top: 4px;
  font-family: var(--mono);
}

/* ========== History ========== */
.history {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg-elev);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.history-item__date {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 12px;
}

.history-item__stats {
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
}

.badge {
  font-size: 11px;
  padding: 4px 10px;
  background: var(--bg-elev);
  border-radius: 12px;
  color: var(--text-dim);
  font-family: var(--mono);
}

.empty {
  text-align: center;
  padding: 24px 16px;
  color: var(--text-faint);
  font-size: 13px;
}

.empty__sub {
  font-size: 11px;
  margin-top: 4px;
}

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn--primary {
  background: var(--accent);
  color: white;
}

.btn--primary:hover, .btn--primary:active {
  background: #e64a19;
}

.btn--primary:disabled {
  background: var(--bg-elev);
  color: var(--text-faint);
  cursor: not-allowed;
}

.btn--ghost {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn--ghost:hover, .btn--ghost:active {
  background: var(--border);
}

.btn--small {
  padding: 6px 12px;
  font-size: 12px;
  background: var(--accent);
  color: white;
}

/* ========== Modal ========== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal__panel {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  background: var(--bg-card);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--border);
}

.modal__head h3 {
  font-size: 17px;
  font-weight: 700;
}

.modal__body {
  padding: 18px 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal__foot {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}

.modal__foot .btn {
  flex: 1;
}

/* ========== Form Fields ========== */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.field > span {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
}

.field input, .field textarea, .field select {
  padding: 10px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus, .field textarea:focus {
  border-color: var(--accent);
}

.field textarea {
  resize: vertical;
  min-height: 60px;
  font-family: inherit;
}

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

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.settings-group:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.settings-group h4 {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ========== Toast ========== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 20px;
  background: var(--text);
  color: var(--bg);
  border-radius: 24px;
  font-size: 13px;
  font-weight: 600;
  z-index: 200;
  box-shadow: var(--shadow);
  animation: toastIn 0.3s;
}

@keyframes toastIn {
  from { transform: translateX(-50%) translateY(20px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ========== Responsive ========== */
@media (min-width: 600px) {
  .modal__panel {
    border-radius: 20px;
    margin: auto;
    max-width: 420px;
  }
  .modal {
    align-items: center;
  }
}

@media (max-width: 380px) {
  .timer-display {
    font-size: 52px;
  }
  .summary {
    grid-template-columns: repeat(2, 1fr);
  }
}
