/* ─────────────────────────────────────────
   DayScore — style.css
   ───────────────────────────────────────── */

:root {
  --font-mono: 'IBM Plex Mono', 'Fira Mono', 'Menlo', monospace;
  --font-sans: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --container-width: 680px;
  --text-xs:   0.70rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   2.8rem;
  --space-1: 0.25rem; --space-2: 0.5rem;  --space-3: 0.75rem;
  --space-4: 1rem;    --space-5: 1.25rem; --space-6: 1.5rem;
  --space-8: 2rem;    --space-10: 2.5rem;
  --transition-theme: background-color 0.2s, color 0.2s, border-color 0.2s;
  --radius: 4px;
}

[data-theme="light"] {
  --bg:              #fafaf8;
  --bg-subtle:       #f2f2ef;
  --border:          #e4e4e0;
  --text-primary:    #141412;
  --text-secondary:  #505048;
  --text-muted:      #9a9a90;
  --text-done:       #c0c0b4;
  --accent-score:    #141412;
  --score-unit-color:#9a9a90;
  --ring-track:      #e8e8e4;
  --ring-fill:       #141412;
  --ring-cap:        #141412;
  --modal-bg:        #ffffff;
  --modal-shadow:    0 12px 48px rgba(0,0,0,0.10);
  --btn-bg:          #141412;
  --btn-color:       #ffffff;
  --btn-cancel-bg:   #e8e8e4;
  --btn-cancel-color:#505048;
  --editor-bg:       #fafaf8;
  --editor-border:   #d4d4ce;
  --overlay-bg:      rgba(250,250,248,0.88);
  --habit-hover:     #f2f2ef;
  --score-badge-bg:  #f0f0ec;
  --score-badge-color:#6a6a60;
  --check-border:    #c0c0b4;
  --check-fill:      #505048;
  --history-ring-track: #e8e8e4;
  --history-ring-fill:  #141412;
  --history-cell-bg:    #f5f5f2;
  --history-cell-hover: #ebebе7;
  --history-today-border: #141412;
}

[data-theme="dark"] {
  --bg:              #0d0d0b;
  --bg-subtle:       #161614;
  --border:          #252521;
  --text-primary:    #ebebdf;
  --text-secondary:  #a8a89a;
  --text-muted:      #555550;
  --text-done:       #3a3a36;
  --accent-score:    #ebebdf;
  --score-unit-color:#555550;
  --ring-track:      #1e1e1a;
  --ring-fill:       #ebebdf;
  --ring-cap:        #ebebdf;
  --modal-bg:        #0d0d0b;
  --modal-shadow:    0 12px 48px rgba(0,0,0,0.7);
  --btn-bg:          #ebebdf;
  --btn-color:       #0d0d0b;
  --btn-cancel-bg:   #252521;
  --btn-cancel-color:#a8a89a;
  --editor-bg:       #080806;
  --editor-border:   #2e2e2a;
  --overlay-bg:      rgba(13,13,11,0.92);
  --habit-hover:     #161614;
  --score-badge-bg:  #1e1e1a;
  --score-badge-color:#666660;
  --check-border:    #444440;
  --check-fill:      #a8a89a;
  --history-ring-track: #1e1e1a;
  --history-ring-fill:  #ebebdf;
  --history-cell-bg:    #141412;
  --history-cell-hover: #1c1c1a;
  --history-today-border: #ebebdf;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 16px;
  transition: var(--transition-theme);
}

/* ── App wrapper ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: var(--container-width);
  margin: 0 auto;
  padding: 0 var(--space-6);
}

/* ── Status panel ── */
#status-panel {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  padding: var(--space-5) 0 var(--space-4);
  transition: var(--transition-theme);
}

/* ── Score layout: ring left, text right ── */
#score-layout {
  display: flex;
  align-items: center;
  gap: var(--space-6);
}

/* ── Ring ── */
#ring-wrap {
  flex-shrink: 0;
  width: 100px;
  height: 100px;
}

#score-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg); /* start from top */
}

.ring-track {
  fill: none;
  stroke: var(--ring-track);
  stroke-width: 10;
  transition: stroke 0.2s;
}

.ring-fill {
  fill: none;
  stroke: var(--ring-fill);
  stroke-width: 10;
  stroke-linecap: round;
  /* circumference of r=52: 2 * pi * 52 ≈ 326.73 */
  stroke-dasharray: 326.73;
  stroke-dashoffset: 326.73; /* starts empty */
  transition: stroke-dashoffset 0.6s ease, stroke 0.2s;
}

/* ── Score text ── */
#score-text {
  flex: 1;
  min-width: 0;
}

#score-label {
  font-size: var(--text-xs);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--space-1);
  font-family: var(--font-mono);
}

#score-display {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-weight: 400;
  line-height: 1.0;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-1);
}

#score-value { color: var(--accent-score); transition: color 0.3s; }
#score-unit  { color: var(--score-unit-color); font-size: 1.4rem; margin-left: 2px; }

#score-subtext {
  font-size: var(--text-sm);
  color: var(--text-muted);
  font-family: var(--font-mono);
  min-height: 1.3em;
  margin-bottom: var(--space-2);
}

/* ── Stats bar ── */
#stats-bar {
  display: flex;
  gap: var(--space-4);
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ── Habits container ── */
#habits-container {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: none;
}
#habits-container::-webkit-scrollbar { display: none; }
#habits-list { padding: var(--space-8) 0 var(--space-10); }

/* ── Habit row ── */
.habit-row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-2);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
  margin: 0 calc(var(--space-2) * -1);
  user-select: none;
}
.habit-row:hover { background: var(--habit-hover); }

.habit-check {
  flex-shrink: 0;
  width: 1.1rem;
  height: 1.1rem;
  border: 1.5px solid var(--check-border);
  border-radius: 3px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  margin-top: 1px;
}
.habit-row.done .habit-check {
  background: var(--check-fill);
  border-color: var(--check-fill);
}
.habit-row.done .habit-check::after {
  content: '';
  display: block;
  width: 0.38em;
  height: 0.62em;
  border: 1.5px solid var(--bg);
  border-top: none;
  border-left: none;
  transform: rotate(45deg) translateY(-1px);
}

.habit-content {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  min-width: 0;
}
.habit-name {
  font-size: var(--text-base);
  color: var(--text-secondary);
  line-height: 1.4;
  transition: color 0.15s, opacity 0.15s;
  flex: 1;
  min-width: 0;
}
.habit-row.done .habit-name {
  color: var(--text-done);
  text-decoration: line-through;
  text-decoration-color: var(--text-done);
  opacity: 0.7;
}
.habit-score-badge {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--score-badge-color);
  background: var(--score-badge-bg);
  border-radius: 3px;
  padding: 1px 6px;
  letter-spacing: 0.04em;
}
.habit-points {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  min-width: 3rem;
  text-align: right;
}
.habit-row.done .habit-points { color: var(--check-fill); }

/* ── Controls ── */
#controls {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  z-index: 10;
}
#btn-reset, #btn-history, #btn-link, #btn-edit {
  border: none;
  background: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  opacity: 0.5;
  padding: 0;
  transition: opacity 0.2s;
  line-height: 1;
}
#btn-reset:hover, #btn-history:hover, #btn-link:hover, #btn-edit:hover { opacity: 1; }

#theme-toggle {
  width: 1.125rem; height: 1.125rem;
  border-radius: 50%; border: none; background: none;
  cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
  opacity: 0.45; transition: opacity 0.2s;
}
#theme-toggle:hover { opacity: 1; }
[data-theme="light"] #theme-icon {
  display: block; width: 0.875rem; height: 0.875rem;
  border-radius: 50%; background: #111;
}
[data-theme="dark"] #theme-icon {
  display: block; width: 0.875rem; height: 0.875rem;
  border-radius: 50%; background: transparent; border: 1.5px solid #ccc;
}

/* ── Edit modal ── */
#modal-overlay {
  position: fixed; inset: 0;
  background: var(--overlay-bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
  transition: var(--transition-theme);
}
#modal-overlay.hidden { display: none; }

#modal {
  width: min(var(--container-width), calc(100vw - var(--space-6) * 2));
  background: var(--modal-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--modal-shadow);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: var(--transition-theme);
}
#modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}
#modal-title {
  font-size: var(--text-xs); font-weight: 600;
  letter-spacing: 0.10em; text-transform: uppercase;
  color: var(--text-muted); font-family: var(--font-mono);
}
#modal-hint {
  font-size: var(--text-xs); color: var(--text-muted); font-family: var(--font-mono);
}
#plan-editor {
  width: 100%; min-height: 22rem; max-height: 55vh;
  background: var(--editor-bg);
  border: none; border-bottom: 1px solid var(--editor-border);
  color: var(--text-primary);
  font-family: var(--font-mono); font-size: var(--text-base);
  line-height: 1.75;
  padding: var(--space-4) var(--space-5);
  resize: vertical; outline: none; tab-size: 2;
  transition: var(--transition-theme);
}
#modal-footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: var(--space-3) var(--space-5); gap: var(--space-4);
}
#modal-format-hint {
  font-size: var(--text-xs); color: var(--text-muted);
  font-family: var(--font-mono); flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#modal-actions { display: flex; gap: var(--space-2); flex-shrink: 0; }
#btn-cancel, #btn-save {
  border: none; border-radius: var(--radius);
  font-family: var(--font-sans); font-size: var(--text-sm); font-weight: 500;
  padding: var(--space-2) var(--space-4); cursor: pointer; transition: opacity 0.15s;
}
#btn-cancel:hover, #btn-save:hover { opacity: 0.75; }
#btn-cancel { background: var(--btn-cancel-bg); color: var(--btn-cancel-color); }
#btn-save   { background: var(--btn-bg); color: var(--btn-color); }

/* ── History modal ── */
#history-overlay {
  position: fixed; inset: 0;
  background: var(--overlay-bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
  transition: var(--transition-theme);
}
#history-overlay.hidden { display: none; }

#history-modal {
  width: min(720px, calc(100vw - var(--space-6) * 2));
  max-height: 80vh;
  background: var(--modal-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--modal-shadow);
  display: flex; flex-direction: column;
  overflow: hidden;
}
#history-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#history-title {
  font-size: var(--text-xs); font-weight: 600;
  letter-spacing: 0.10em; text-transform: uppercase;
  color: var(--text-muted); font-family: var(--font-mono);
}
#history-close {
  border: none; background: none; cursor: pointer;
  font-size: var(--text-sm); color: var(--text-muted);
  opacity: 0.5; padding: 0; line-height: 1;
  transition: opacity 0.15s;
}
#history-close:hover { opacity: 1; }

#history-body {
  overflow-y: auto; padding: var(--space-5);
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#history-loading {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-muted);
  padding: var(--space-4) 0;
}

#history-empty {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-muted);
  padding: var(--space-4) 0;
}

/* ── History grid ── */
#history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--space-3);
}

.history-cell {
  background: var(--history-cell-bg);
  border-radius: 6px;
  padding: var(--space-3);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  border: 1.5px solid transparent;
  text-decoration: none;
}
.history-cell:hover {
  background: var(--history-cell-hover);
  transform: translateY(-1px);
}
.history-cell.today {
  border-color: var(--history-today-border);
}

.history-cell-ring {
  width: 64px;
  height: 64px;
}
.history-cell-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.history-cell-ring .h-ring-track {
  fill: none;
  stroke: var(--history-ring-track);
  stroke-width: 8;
}
.history-cell-ring .h-ring-fill {
  fill: none;
  stroke: var(--history-ring-fill);
  stroke-width: 8;
  stroke-linecap: round;
  /* r=28: circumference ≈ 175.93 */
  stroke-dasharray: 175.93;
  stroke-dashoffset: 175.93;
  transition: stroke-dashoffset 0.4s ease;
}

.history-cell-date {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-align: center;
  line-height: 1.3;
}
.history-cell-score {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
}
.history-cell.today .history-cell-date {
  color: var(--text-primary);
  font-weight: 500;
}

/* ── Empty state ── */
.empty-state {
  padding: var(--space-10) 0;
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-family: var(--font-mono);
  line-height: 1.8;
}
.empty-state strong { color: var(--text-secondary); font-weight: 500; }

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Toast ── */
#share-toast {
  position: fixed; bottom: var(--space-6); left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary); color: var(--bg);
  font-size: var(--text-xs); font-family: var(--font-mono);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius); white-space: nowrap;
  opacity: 1; transition: opacity 0.5s ease; z-index: 200;
}
#share-toast.toast-fade { opacity: 0; }

/* ── Reset confirmation modal ── */
#reset-overlay {
  position: fixed; inset: 0;
  background: var(--overlay-bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
  transition: var(--transition-theme);
}
#reset-overlay.hidden { display: none; }

#reset-modal {
  width: min(360px, calc(100vw - var(--space-6) * 2));
  background: var(--modal-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--modal-shadow);
  overflow: hidden;
}

#reset-header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}

#reset-title {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

#reset-body {
  padding: var(--space-4) var(--space-5);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.5;
}

#reset-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
}

#btn-reset-cancel, #btn-reset-confirm {
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  padding: var(--space-2) var(--space-4);
  cursor: pointer;
  transition: opacity 0.15s;
}
#btn-reset-cancel:hover, #btn-reset-confirm:hover { opacity: 0.75; }
#btn-reset-cancel  { background: var(--btn-cancel-bg);  color: var(--btn-cancel-color); }
#btn-reset-confirm { background: var(--btn-bg);          color: var(--btn-color); }
