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

    /* ── DARK THEME (default) — warm brown-black ── */
    :root {
      --accent:      #e85d3a;
      --accent-dark: #c94825;
      --accent-soft: rgba(232, 93, 58, 0.12);
      --bg:          #1c1714;
      --surface:     #252119;
      --surface2:    #2e2a23;
      --border:      rgba(255,255,255,0.07);
      --border2:     rgba(255,255,255,0.13);
      --text:        #ede8e1;
      --text2:       #a09890;
      --text3:       #6a6158;
      --success:     #4ade80;
      --error:       #f87171;
      --pie-hole:    #252119;
      --radius:      14px;
      --radius-sm:   9px;
      --font:        'DM Sans', sans-serif;
      --mono:        'DM Mono', monospace;
    }

    /* ── LIGHT THEME — warm cream/parchment ── */
    :root.light {
      --accent:      #d94f2a;
      --accent-dark: #b83e1e;
      --accent-soft: rgba(217, 79, 42, 0.1);
      --bg:          #f0ebe3;
      --surface:     #faf7f2;
      --surface2:    #f0ebe3;
      --border:      rgba(60,40,20,0.09);
      --border2:     rgba(60,40,20,0.15);
      --text:        #211c15;
      --text2:       #6b6055;
      --text3:       #a89e92;
      --success:     #16a34a;
      --error:       #dc2626;
      --pie-hole:    #faf7f2;
    }

    /* ── EVENING THEME — lighter warm cream / dusk ── */
    :root.evening {
      --accent:      #e07828;
      --accent-dark: #c46318;
      --accent-soft: rgba(224, 120, 40, 0.14);
      --bg:          #4a443c;
      --surface:     #585248;
      --surface2:    #625c52;
      --border:      rgba(255, 245, 220, 0.12);
      --border2:     rgba(255, 245, 220, 0.22);
      --text:        #faf4e8;
      --text2:       #ddd2bc;
      --text3:       #a8987c;
      --success:     #5ee9b5;
      --error:       #f8a8a8;
      --pie-hole:    #585248;
    }

    body {
      font-family: var(--font);
      background: var(--bg);
      color: var(--text);
      min-height: 100dvh;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
      transition: background 0.25s, color 0.25s;
    }

    /* ── LOGIN ── */
    #login-overlay {
      position: fixed;
      inset: 0;
      background: var(--bg);
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 100;
      padding: 1.5rem;
      transition: background 0.25s;
    }
    #login-overlay.hidden { display: none; }

    .login-card {
      background: var(--surface);
      border: 1px solid var(--border2);
      border-radius: var(--radius);
      padding: 2rem 1.75rem;
      width: 100%;
      max-width: 340px;
    }

    .login-card-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 0.75rem;
      margin-bottom: 0.35rem;
    }
    .login-card-header .wordmark {
      font-size: 0.7rem;
      font-weight: 500;
      letter-spacing: 0.15em;
      text-transform: uppercase;
      color: var(--accent);
      margin-bottom: 0;
    }
    .login-theme-btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 34px;
      height: 34px;
      padding: 0;
      border-radius: 8px;
      border: 1px solid var(--border2);
      background: var(--surface2);
      cursor: pointer;
      color: var(--text2);
      font-size: 0.9rem;
      font-family: inherit;
      line-height: 1;
      flex-shrink: 0;
      transition: border-color 0.15s, color 0.15s, background 0.15s;
      -webkit-tap-highlight-color: transparent;
    }
    .login-theme-btn:hover {
      border-color: var(--accent);
      color: var(--accent);
      background: var(--accent-soft);
    }
    .login-theme-btn:focus {
      outline: none;
    }
    .login-theme-btn:focus-visible {
      outline: 2px solid var(--accent);
      outline-offset: 2px;
    }

    .login-card h2 {
      font-size: 1.45rem;
      font-weight: 600;
      letter-spacing: -0.02em;
      color: var(--text);
      margin-bottom: 1.75rem;
    }

    .auth-switch {
      margin-top: 1rem;
      font-size: 0.8rem;
      color: var(--text2);
      text-align: center;
    }
    .auth-switch a { color: var(--accent); text-decoration: none; }
    .auth-switch a:hover { text-decoration: underline; }

    .forgot-password-wrap {
      margin-top: 0.65rem;
      text-align: center;
    }
    .forgot-password-panel {
      display: none;
      margin-top: 0.55rem;
      padding: 0.65rem 0.75rem;
      font-size: 0.75rem;
      line-height: 1.45;
      color: var(--text2);
      text-align: left;
      background: var(--surface2);
      border-radius: var(--radius-sm);
      border: 1px solid var(--border);
    }
    .forgot-password-panel.open { display: block; }

    /* ── APP SHELL ── */
    #app {
      display: none;
      width: 100%;
      max-width: 520px;
      flex-direction: column;
      align-items: stretch;
      gap: 0.75rem;
      padding: 0.75rem 0.75rem 4rem;
    }

    .app-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0.75rem 0.25rem 0.5rem;
      gap: 0.5rem;
    }

    .app-header-left .wordmark {
      font-size: 0.62rem;
      font-weight: 500;
      letter-spacing: 0.15em;
      text-transform: uppercase;
      color: var(--accent);
      margin-bottom: 0.15rem;
    }

    h1 {
      font-size: 1.15rem;
      font-weight: 600;
      letter-spacing: -0.02em;
      color: var(--text);
    }

    .header-actions {
      display: flex;
      gap: 0.4rem;
      align-items: center;
      flex-shrink: 0;
    }

    /* ── UNIFIED HEADER BUTTON (theme toggle, API, logout) ── */
    .header-btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      height: 34px;
      padding: 0 0.7rem;
      border-radius: 8px;
      border: 1px solid var(--border2);
      background: var(--surface2);
      cursor: pointer;
      color: var(--text2);
      font-size: 0.8rem;
      font-weight: 500;
      font-family: var(--font);
      text-decoration: none;
      white-space: nowrap;
      min-height: 0;
      transition: border-color 0.15s, color 0.15s, background 0.15s;
      flex-shrink: 0;
      letter-spacing: -0.01em;
    }
    .header-btn:hover {
      border-color: var(--accent);
      color: var(--accent);
      background: var(--accent-soft);
    }
    /* icon-only variant for theme toggle */
    .header-btn.icon-only {
      width: 34px;
      padding: 0;
      font-size: 0.9rem;
    }

    /* ── CARD ── */
    .card {
      background: var(--surface);
      border-radius: var(--radius);
      border: 1px solid var(--border);
      overflow: hidden;
      transition: background 0.25s, border-color 0.25s;
    }

    .card-inner { padding: 1.25rem; }

    .section-label {
      font-size: 0.6rem;
      font-weight: 500;
      text-transform: uppercase;
      letter-spacing: 0.14em;
      color: var(--text3);
      margin-bottom: 1rem;
    }

    /* ── TIMER ── */
    .timer-body { padding: 1.5rem 1.25rem 1.25rem; }

    .timer-top {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      margin-bottom: 1.25rem;
      gap: 0.75rem;
    }

    .timer-meta { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; }

    .timer-state {
      font-size: 0.6rem;
      font-weight: 500;
      letter-spacing: 0.14em;
      text-transform: uppercase;
      color: var(--text3);
    }

    .timer-activity {
      font-size: 1.3rem;
      font-weight: 600;
      letter-spacing: -0.02em;
      color: var(--text);
      min-height: 1.8rem;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .timer-activity.inactive { color: var(--text3); font-weight: 300; font-style: italic; }

    .timer-since {
      font-size: 0.75rem;
      color: var(--text2);
      font-family: var(--mono);
      margin-top: 0.15rem;
      min-height: 1.1rem;
    }

    .timer-elapsed-wrap { text-align: right; flex-shrink: 0; }

    .timer-elapsed {
      font-size: 2.4rem;
      font-weight: 400;
      font-family: var(--mono);
      letter-spacing: -0.03em;
      color: var(--accent);
      line-height: 1;
    }
    .timer-elapsed.inactive { color: var(--text3); }

    .label-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
      gap: 0.4rem;
      margin-bottom: 0.85rem;
    }

    .label-btn {
      padding: 0.6rem 0.5rem;
      border-radius: var(--radius-sm);
      border: 1px solid var(--border2);
      background: var(--surface2);
      color: var(--text2);
      font-size: 0.8rem;
      font-weight: 500;
      font-family: var(--font);
      cursor: pointer;
      transition: all 0.15s;
      min-height: 42px;
      text-align: center;
      -webkit-tap-highlight-color: transparent;
      letter-spacing: -0.01em;
    }
    .label-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
    .label-btn:active { transform: scale(0.96); }
    .label-btn.active-label { background: var(--accent); border-color: var(--accent); color: #fff; }

    .timer-footer {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      min-height: 2rem;
    }

    /* ── ACCORDION ── */
    .accordion-trigger {
      display: flex;
      justify-content: space-between;
      align-items: center;
      width: 100%;
      padding: 0.9rem 1.25rem;
      background: none;
      border: none;
      cursor: pointer;
      color: var(--text2);
      font-size: 0.82rem;
      font-weight: 500;
      font-family: var(--font);
      text-align: left;
      border-radius: 0;
      min-height: 0;
      transition: background 0.1s, color 0.1s;
      gap: 0.5rem;
    }
    .accordion-trigger:hover { background: var(--surface2); color: var(--text); }

    .accordion-trigger-left { display: flex; align-items: center; gap: 0.55rem; }

    .chevron { transition: transform 0.2s ease; color: var(--text3); flex-shrink: 0; }
    .accordion-trigger[aria-expanded="true"] .chevron { transform: rotate(180deg); }

    .accordion-body { display: none; border-top: 1px solid var(--border); }
    .accordion-body.open { display: block; }

    /* ── LABELS INNER ── */
    .labels-inner { padding: 0 1.25rem 1.25rem; }

    .label-chips {
      display: flex;
      flex-wrap: wrap;
      gap: 0.35rem;
      margin-bottom: 0.85rem;
      padding-top: 0.9rem;
    }

    .chip {
      display: inline-flex;
      align-items: center;
      gap: 0.25rem;
      padding: 0.28rem 0.5rem 0.28rem 0.65rem;
      background: var(--surface2);
      border-radius: 99px;
      font-size: 0.78rem;
      color: var(--text2);
      border: 1px solid var(--border2);
    }

    .chip-delete {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      background: none;
      border: none;
      cursor: pointer;
      color: var(--text3);
      padding: 0;
      font-size: 0.85rem;
      line-height: 1;
      width: auto;
      margin: 0;
      min-height: 0;
      transition: color 0.15s;
    }
    .chip-delete:hover { color: var(--error); background: none; }

    .add-label-row { display: flex; gap: 0.5rem; }
    .add-label-row input { flex: 1; margin-bottom: 0; }

    /* ── HISTORY INNER ── */
    .history-inner { padding: 1.1rem 1.25rem 1.25rem; }

    .history-filter {
      display: grid;
      grid-template-columns: 1fr 1fr auto;
      gap: 0.4rem;
      align-items: flex-end;
      margin-bottom: 1rem;
    }
    .history-filter .field { margin-bottom: 0; }

    .event-list { display: flex; flex-direction: column; gap: 0.4rem; }

    .event-row {
      display: grid;
      grid-template-areas:
        "dot info  actions"
        "dot time  duration";
      grid-template-columns: auto 1fr auto;
      grid-template-rows: auto auto;
      column-gap: 0.6rem;
      row-gap: 0.1rem;
      padding: 0.7rem 0.85rem;
      background: var(--surface2);
      border-radius: var(--radius-sm);
      border: 1px solid var(--border);
      align-items: center;
    }

    .event-dot {
      grid-area: dot;
      width: 7px; height: 7px;
      border-radius: 50%;
      flex-shrink: 0;
      background: var(--accent);
      align-self: start;
      margin-top: 5px;
    }

    .event-label-text {
      grid-area: info;
      font-size: 0.875rem;
      font-weight: 600;
      color: var(--text);
      letter-spacing: -0.01em;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .event-time {
      grid-area: time;
      font-size: 0.72rem;
      color: var(--text2);
      font-family: var(--mono);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .event-duration {
      grid-area: duration;
      font-size: 0.72rem;
      font-family: var(--mono);
      font-weight: 500;
      color: var(--text3);
      text-align: right;
      white-space: nowrap;
    }

    .event-actions { grid-area: actions; display: flex; gap: 0.3rem; flex-shrink: 0; }

    .icon-btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 28px; height: 28px;
      border-radius: 7px;
      border: 1px solid var(--border2);
      background: var(--surface);
      cursor: pointer;
      color: var(--text3);
      font-size: 0.78rem;
      min-height: 0;
      padding: 0;
      transition: all 0.15s;
      flex-shrink: 0;
    }
    .icon-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
    .icon-btn.danger:hover { border-color: var(--error); color: var(--error); background: rgba(248,113,113,0.08); }

    .event-edit-form {
      display: flex;
      flex-direction: column;
      gap: 0.65rem;
      padding: 1rem;
      background: var(--surface2);
      border-radius: var(--radius-sm);
      border: 1px solid var(--border2);
    }
    .event-edit-form .field { margin-bottom: 0; }

    .two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
    .event-edit-actions { display: flex; gap: 0.5rem; padding-top: 0.1rem; }

    /* ── STATS INNER ── */
    .stats-inner { padding: 1.1rem 1.25rem 1.25rem; }

    .tabs {
      display: flex;
      background: var(--surface2);
      border-radius: var(--radius-sm);
      padding: 3px; gap: 3px;
      margin-bottom: 1.1rem;
    }

    .tab {
      flex: 1;
      padding: 0.42rem 0;
      border: none;
      border-radius: 7px;
      background: transparent;
      font-size: 0.8rem;
      font-weight: 500;
      font-family: var(--font);
      cursor: pointer;
      color: var(--text3);
      transition: all 0.15s;
      min-height: 0;
      width: auto;
    }
    .tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,0.15); }

    .tab-panel { display: none; }
    .tab-panel.active { display: block; }

    .stats-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-bottom: 1.1rem; }

    .stat-summary-cell {
      padding: 0.75rem 0.9rem;
      background: var(--surface2);
      border-radius: var(--radius-sm);
      border: 1px solid var(--border);
    }
    .stat-summary-label { font-size: 0.62rem; color: var(--text3); font-weight: 500; text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 0.3rem; }
    .stat-summary-value { font-size: 1.05rem; font-weight: 600; letter-spacing: -0.02em; font-family: var(--mono); }

    .pie-wrap { display: flex; justify-content: center; margin-bottom: 1.25rem; }
    .pie-wrap svg { overflow: visible; }

    .stat-row { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.85rem; }
    .stat-header { display: flex; justify-content: space-between; align-items: baseline; font-size: 0.85rem; gap: 0.5rem; }
    .stat-label-wrap { display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
    .stat-label { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .stat-meta { color: var(--text3); font-size: 0.74rem; font-family: var(--mono); white-space: nowrap; flex-shrink: 0; }
    .stat-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

    .bar-wrap { background: var(--surface2); border-radius: 4px; height: 4px; width: 100%; overflow: hidden; }
    .bar { height: 100%; border-radius: 4px; transition: width 0.5s cubic-bezier(0.16,1,0.3,1); }

    /* ── FORM ELEMENTS ── */
    .field { margin-bottom: 0.8rem; }

    label {
      display: block;
      font-size: 0.62rem;
      font-weight: 500;
      letter-spacing: 0.08em;
      text-transform: uppercase;
      color: var(--text3);
      margin-bottom: 0.35rem;
    }

    select,
    input[type="date"],
    input[type="text"],
    input[type="password"],
    input[type="datetime-local"] {
      width: 100%;
      padding: 0.6rem 0.75rem;
      border: 1px solid var(--border2);
      border-radius: var(--radius-sm);
      font-size: max(16px, 0.875rem);
      font-family: var(--font);
      background: var(--surface2);
      color: var(--text);
      outline: none;
      transition: border-color 0.15s, background 0.15s;
      -webkit-appearance: none;
      appearance: none;
    }

    select {
      cursor: pointer;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236e6a66' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
      background-repeat: no-repeat;
      background-position: right 0.75rem center;
      padding-right: 2.25rem;
    }

    select:focus, input:focus {
      border-color: var(--accent);
      outline: none;
      box-shadow: 0 0 0 3px var(--accent-soft);
    }

    /* ── BUTTONS ── */
    button {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      padding: 0.62rem 1.1rem;
      border: none;
      border-radius: var(--radius-sm);
      background: var(--accent);
      color: #fff;
      font-size: 0.875rem;
      font-weight: 600;
      font-family: var(--font);
      cursor: pointer;
      transition: background 0.15s, transform 0.1s, opacity 0.15s;
      white-space: nowrap;
      min-height: 42px;
      -webkit-tap-highlight-color: transparent;
      letter-spacing: -0.01em;
    }

    button.full { width: 100%; }
    button:active { transform: scale(0.97); }
    button:hover { background: var(--accent-dark); }

    button.secondary {
      background: var(--surface2);
      color: var(--text2);
      border: 1px solid var(--border2);
      font-size: 0.8rem;
      min-height: 36px;
      padding: 0.38rem 0.85rem;
    }
    button.secondary:hover { background: var(--border2); color: var(--text); }

    button.danger { background: var(--error); }
    button.danger:hover { background: #e05050; }

    button.sm { font-size: 0.8rem; min-height: 36px; padding: 0.35rem 0.85rem; }

    /* Link-style control (must follow global `button` rules so it isn’t a big orange block) */
    button.forgot-password-toggle {
      display: inline;
      padding: 0;
      margin: 0;
      min-height: 0;
      border: none;
      border-radius: 0;
      background: transparent;
      color: var(--accent);
      font-family: inherit;
      font-size: 0.8rem;
      font-weight: inherit;
      letter-spacing: normal;
      white-space: normal;
      cursor: pointer;
      text-decoration: none;
      outline: none;
      -webkit-tap-highlight-color: transparent;
      transition: none;
    }
    button.forgot-password-toggle:hover {
      background: transparent;
      color: var(--accent);
      text-decoration: underline;
    }
    button.forgot-password-toggle:focus-visible {
      text-decoration: underline;
      outline: none;
    }
    button.forgot-password-toggle:active {
      transform: none;
      background: transparent;
    }

    /* ── MISC ── */
    .status { margin-top: 0.6rem; font-size: 0.78rem; min-height: 1.1rem; color: var(--success); }
    .status.error { color: var(--error); }

    .empty { font-size: 0.8rem; color: var(--text3); font-style: italic; text-align: center; padding: 0.75rem 0; }

    hr { border: none; border-top: 1px solid var(--border); margin: 0.9rem 0; }

    .row { display: flex; gap: 0.5rem; }
    .row .field { flex: 1; }

    .header-btn svg { display: block; }

    /* Settings page */
    .settings-page {
      width: 100%;
      max-width: 520px;
      margin: 0 auto;
      padding: 0.75rem 0.75rem 3rem;
      min-height: 100dvh;
      box-sizing: border-box;
    }
    .settings-header-left {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      gap: 0.35rem;
      min-width: 0;
    }
    .settings-header-left h1 {
      margin: 0;
      font-size: 1.15rem;
    }
    .settings-hint {
      font-size: 0.8rem;
      color: var(--text2);
      line-height: 1.5;
      margin-bottom: 1rem;
    }
    .settings-danger-card {
      border-color: rgba(248, 113, 113, 0.35);
      background: linear-gradient(180deg, rgba(248, 113, 113, 0.06) 0%, transparent 40%);
    }
    .settings-danger-card .section-label {
      color: var(--error);
    }
