:root {
      --bg: #eee9e2;
      --card: #f5f1eb;
      --text: #414247;
      --muted: #6f6b69;
      --border: #dcd5cd;

      --pink: #d989a6;
      --pink-soft: #f8e8ee;

      --blue: #719fc8;
      --blue-soft: #e9f2f8;

      --coral: #dc8979;
      --coral-soft: #faebe7;

      --yellow: #d8b83f;
      --yellow-soft: #fbf5d9;

      --emerald: #5e9d7c;
      --emerald-soft: #e8f3ed;

      --lavender: #9a83bd;
      --lavender-soft: #f0ebf7;

      --accent: var(--coral);
      --accent-soft: var(--coral-soft);

      --radius: 18px;
    }

    * {
      box-sizing: border-box;
    }

    html {
      -webkit-text-size-adjust: 100%;
    }

    body {
      margin: 0;
      background: var(--bg);
      color: var(--text);
      font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
      font-size: 16px;
      -webkit-font-smoothing: antialiased;
    }

    body.font-clean {
      font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    }

    body.font-soft {
      font-family:
        "Avenir Next",
        "Trebuchet MS",
        -apple-system,
        BlinkMacSystemFont,
        sans-serif;
    }

    body.font-journal {
      font-family:
        Georgia,
        "Times New Roman",
        serif;
    }

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

    button {
      -webkit-tap-highlight-color: transparent;
      cursor: pointer;
    }

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

    .hidden {
      display: none !important;
    }

    .shell {
      width: 100%;
      max-width: 680px;
      margin: 0 auto;
      min-height: 100vh;
      padding-bottom:
        calc(82px + env(safe-area-inset-bottom));
    }

    .topbar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding:
        calc(16px + env(safe-area-inset-top))
        18px
        10px;
    }

    .brand {
      min-width: 0;
    }

    .brand h1 {
      margin: 0;
      font-size: 25px;
      line-height: 1.1;
      font-weight: 700;
      letter-spacing: -.02em;
    }

    .brand-name {
      color: var(--text);
    }

    .welcome {
      margin-top: 4px;
      color: var(--muted);
      font-size: 13px;
    }

    .icon-button {
      width: 44px;
      height: 44px;
      border: 0;
      border-radius: 50%;
      background: transparent;
      color: var(--muted);
      font-size: 22px;
    }

    .page {
      display: none;
      padding: 6px 16px 28px;
    }

    .page.active {
      display: block;
    }

    .card {
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      padding: 17px;
      margin-bottom: 13px;
    }

    .section-title {
      margin: 0 0 11px;
      font-size: 17px;
      font-weight: 700;
    }

    .small-title {
      margin: 0 0 7px;
      font-size: 13px;
      font-weight: 700;
      color: #65656a;
    }

    .field-label {
      display: block;
      margin: 0 0 7px;
      font-size: 13px;
      font-weight: 700;
      color: #65656a;
    }

    .text-input,
    .text-area,
    .time-input {
      width: 100%;
      border: 1px solid var(--border);
      border-radius: 14px;
      background: #f8f4ee;
      color: var(--text);
      outline: none;
    }

    .text-input,
    .time-input {
      min-height: 48px;
      padding: 11px 13px;
    }

    .text-area {
      min-height: 94px;
      padding: 12px 13px;
      line-height: 1.42;
      resize: vertical;
    }

    .text-input:focus,
    .text-area:focus,
    .time-input:focus {
      border-color: var(--accent);
      box-shadow:
        0 0 0 3px var(--accent-soft);
    }

    .truth-area {
      background: #f6f1e7;
    }

    .hint {
      margin-top: 6px;
      color: var(--muted);
      font-size: 12px;
      line-height: 1.35;
    }

    .type-grid {
      display: grid;
      grid-template-columns: 1fr;
      gap: 8px;
    }

    .type-button {
      min-height: 48px;
      border: 2px solid transparent;
      border-radius: 14px;
      padding: 10px 12px;
      text-align: left;
      font-weight: 650;
      transition:
        border-color .12s ease,
        transform .12s ease;
    }

    .type-button.selected {
      border-color: currentColor;
    }

    .intensity-grid {
      display: grid;
      grid-template-columns: repeat(10, 1fr);
      gap: 4px;
    }

    .intensity-button {
      min-width: 0;
      min-height: 42px;
      padding: 0;
      border: 1px solid var(--border);
      border-radius: 10px;
      background: #f5f1eb;
      color: var(--text);
      font-weight: 650;
    }

    .intensity-button.selected {
      background: var(--accent-soft);
      border-color: var(--accent);
      color: var(--text);
    }

    .scale-labels {
      display: flex;
      justify-content: space-between;
      margin-top: 6px;
      padding: 0 2px;
      color: var(--muted);
      font-size: 11px;
    }

    .time-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
    }

    .time-copy {
      min-width: 0;
    }

    .time-copy strong {
      display: block;
      font-size: 15px;
      font-weight: 650;
    }

    .time-copy span {
      display: block;
      margin-top: 2px;
      color: var(--muted);
      font-size: 12px;
    }

    .link-button {
      border: 0;
      background: transparent;
      color: var(--accent);
      font-weight: 700;
      padding: 10px 4px;
    }

    .time-editor {
      margin-top: 13px;
      padding-top: 13px;
      border-top: 1px solid var(--border);
    }

    .time-fields {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 9px;
    }

    .toggle-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      margin-top: 12px;
    }

    .toggle {
      position: relative;
      width: 52px;
      height: 30px;
      flex: 0 0 auto;
    }

    .toggle input {
      opacity: 0;
      width: 0;
      height: 0;
    }

    .toggle-track {
      position: absolute;
      inset: 0;
      border-radius: 30px;
      background: #d8d6d3;
      transition: .18s ease;
    }

    .toggle-track::after {
      content: "";
      position: absolute;
      width: 24px;
      height: 24px;
      top: 3px;
      left: 3px;
      border-radius: 50%;
      background: var(--card);
      box-shadow: 0 1px 3px rgba(0,0,0,.14);
      transition: .18s ease;
    }

    .toggle input:checked + .toggle-track {
      background: var(--accent);
    }

    .toggle input:checked + .toggle-track::after {
      transform: translateX(22px);
    }

    .primary-button {
      width: 100%;
      min-height: 52px;
      border: 0;
      border-radius: 15px;
      background: var(--accent);
      color: white;
      font-weight: 750;
      font-size: 17px;
      padding: 13px 16px;
    }

    .primary-button:disabled {
      opacity: .55;
      cursor: default;
    }

    .secondary-button {
      min-height: 44px;
      border: 1px solid var(--border);
      border-radius: 13px;
      background: var(--card);
      color: var(--text);
      font-weight: 650;
      padding: 10px 13px;
    }

    .danger-button {
      min-height: 44px;
      border: 1px solid #efd3d3;
      border-radius: 13px;
      background: #fffafa;
      color: #a85b5b;
      font-weight: 650;
      padding: 10px 13px;
    }

    .ongoing-wrap {
      margin-bottom: 14px;
    }

    .ongoing-title {
      margin: 0 0 8px;
      color: var(--muted);
      font-size: 12px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: .04em;
    }

    .ongoing-card {
      display: grid;
      grid-template-columns: 1fr auto;
      align-items: center;
      gap: 10px;
      background: var(--card);
      border: 1px solid var(--border);
      border-left: 5px solid var(--accent);
      border-radius: 15px;
      padding: 12px 13px;
      margin-bottom: 8px;
    }

    .ongoing-type {
      font-weight: 700;
      font-size: 14px;
    }

    .ongoing-meta {
      margin-top: 3px;
      color: var(--muted);
      font-size: 12px;
    }

    .end-button {
      min-width: 66px;
      min-height: 42px;
      border: 0;
      border-radius: 12px;
      background: var(--accent-soft);
      color: var(--text);
      font-weight: 750;
    }

    .today-summary {
      margin-top: 14px;
      text-align: center;
      color: var(--muted);
      font-size: 12px;
    }

    .history-filter {
      display: flex;
      gap: 7px;
      overflow-x: auto;
      padding-bottom: 4px;
      scrollbar-width: none;
    }

    .history-filter::-webkit-scrollbar {
      display: none;
    }

    .filter-button,
    .range-button,
    .pattern-tab {
      min-height: 42px;
      white-space: nowrap;
      border: 1px solid var(--border);
      border-radius: 20px;
      background: var(--card);
      color: var(--text);
      padding: 8px 12px;
      font-size: 13px;
      font-weight: 650;
    }

    .filter-button.active,
    .range-button.active,
    .pattern-tab.active {
      background: var(--accent-soft);
      border-color: var(--accent);
    }

    .entry-card {
      position: relative;
      overflow: hidden;
    }

    .entry-accent {
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      width: 5px;
    }

    .entry-time {
      margin-bottom: 11px;
      color: var(--muted);
      font-size: 12px;
    }

    .thought-truth {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 14px;
    }

    .entry-label {
      margin-bottom: 4px;
      color: var(--muted);
      font-size: 11px;
      font-weight: 750;
      letter-spacing: .04em;
      text-transform: uppercase;
    }

    .entry-text {
      line-height: 1.4;
      white-space: pre-wrap;
      overflow-wrap: anywhere;
    }

    .entry-meta {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 6px;
      margin-top: 13px;
      padding-top: 11px;
      border-top: 1px solid var(--border);
    }

    .meta-pill {
      display: inline-flex;
      align-items: center;
      min-height: 27px;
      border-radius: 14px;
      padding: 4px 8px;
      background: #f5f3f1;
      color: #66666b;
      font-size: 12px;
    }

    .entry-edit {
      margin-left: auto;
      border: 0;
      background: transparent;
      color: var(--accent);
      font-size: 13px;
      font-weight: 700;
      padding: 7px 3px;
    }

    .pattern-nav {
      display: flex;
      gap: 7px;
      margin-bottom: 10px;
      overflow-x: auto;
    }

    .range-nav {
      display: flex;
      gap: 7px;
      margin-bottom: 13px;
      overflow-x: auto;
    }

    .stat-grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 8px;
    }

    .stat-card {
      min-width: 0;
      border-radius: 14px;
      background: #f8f6f4;
      padding: 13px 8px;
      text-align: center;
    }

    .stat-value {
      font-size: 23px;
      font-weight: 750;
    }

    .stat-label {
      margin-top: 3px;
      color: var(--muted);
      font-size: 11px;
    }

    .type-bar-row {
      margin: 13px 0;
    }

    .type-bar-label {
      display: flex;
      justify-content: space-between;
      gap: 10px;
      margin-bottom: 5px;
      font-size: 13px;
    }

    .type-bar-track {
      height: 10px;
      overflow: hidden;
      border-radius: 10px;
      background: #f0eeeb;
    }

    .type-bar-fill {
      height: 100%;
      border-radius: 10px;
    }

    .timeline-wrap {
      overflow-x: auto;
      padding-bottom: 5px;
    }

    .timeline {
      min-width: 540px;
    }

    .timeline-axis {
      display: grid;
      grid-template-columns: 78px 1fr;
      align-items: end;
      margin-bottom: 8px;
    }

    .axis-hours {
      position: relative;
      height: 22px;
      color: var(--muted);
      font-size: 10px;
    }

    .axis-hours span {
      position: absolute;
      transform: translateX(-50%);
    }

    .day-row {
      display: grid;
      grid-template-columns: 78px 1fr;
      gap: 8px;
      align-items: center;
      margin: 8px 0;
    }

    .day-label {
      color: #67676c;
      font-size: 12px;
      font-weight: 650;
    }

    .day-track {
      position: relative;
      min-height: 28px;
      border-radius: 8px;
      background: #f6f4f2;
      overflow: hidden;
    }

    .time-segment {
      position: absolute;
      min-width: 2px;
      height: 10px;
      border-radius: 5px;
    }

    .time-segment.lane-0 {
      top: 3px;
    }

    .time-segment.lane-1 {
      top: 15px;
    }

    .intensity-segment {
      position: absolute;
      top: 5px;
      height: 18px;
      min-width: 2px;
      border-radius: 5px;
      background: var(--accent);
    }

    .timeline-note {
      margin-top: 10px;
      color: var(--muted);
      font-size: 11px;
      line-height: 1.4;
    }

    .empty-state {
      padding: 28px 10px;
      text-align: center;
      color: var(--muted);
      font-size: 14px;
    }

    .bottom-nav {
      position: fixed;
      left: 0;
      right:
      0;
      bottom: 0;
      z-index: 20;
      background: rgba(238,233,226,.97);
      border-top: 1px solid var(--border);
      padding-bottom: env(safe-area-inset-bottom);
    }

    .nav-inner {
      width: 100%;
      max-width: 680px;
      margin: 0 auto;
      display: grid;
      grid-template-columns: repeat(3, 1fr);
    }

    .nav-button {
      min-height: 62px;
      border: 0;
      background: transparent;
      color: var(--muted);
      font-size: 12px;
      font-weight: 650;
    }

    .nav-button.active {
      color: var(--accent);
    }

    .auth-shell {
      width: 100%;
      max-width: 430px;
      margin: 0 auto;
      padding:
        calc(44px + env(safe-area-inset-top))
        20px
        30px;
    }

    .auth-title {
      margin: 0;
      text-align: center;
      font-size: 29px;
      letter-spacing: -.02em;
    }

    .auth-subtitle {
      margin: 8px 0 24px;
      text-align: center;
      color: var(--muted);
      line-height: 1.45;
    }

    .auth-tabs {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 7px;
      margin-bottom: 14px;
    }

    .auth-tab {
      min-height: 44px;
      border: 1px solid var(--border);
      border-radius: 13px;
      background: var(--card);
      color: var(--text);
      font-weight: 650;
    }

    .auth-tab.active {
      background: var(--accent-soft);
      border-color: var(--accent);
    }

    .auth-field {
      margin-bottom: 13px;
    }

    .pin-input {
      text-align: center;
      letter-spacing: .35em;
      font-size: 22px;
      font-weight: 700;
    }

    .forgot-button {
      width: 100%;
      margin-top: 9px;
      border: 0;
      background: transparent;
      color: var(--muted);
      padding: 9px;
      font-size: 13px;
    }

    .settings-group {
      margin-bottom: 19px;
    }

    .color-options {
      display: grid;
      grid-template-columns: repeat(6, 1fr);
      gap: 8px;
    }

    .color-choice {
      min-width: 0;
      aspect-ratio: 1;
      border: 3px solid transparent;
      border-radius: 50%;
      padding: 0;
    }

    .color-choice.selected {
      border-color: #6d6d72;
      box-shadow: inset 0 0 0 3px white;
    }

    .color-pink { background: var(--pink); }
    .color-blue { background: var(--blue); }
    .color-coral { background: var(--coral); }
    .color-yellow { background: var(--yellow); }
    .color-emerald { background: var(--emerald); }
    .color-lavender { background: var(--lavender); }

    .font-options {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 8px;
    }

    .font-choice {
      min-height: 50px;
      border: 1px solid var(--border);
      border-radius: 13px;
      background: var(--card);
      color: var(--text);
    }

    .font-choice.selected {
      background: var(--accent-soft);
      border-color: var(--accent);
    }

    .font-clean-preview {
      font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    }

    .font-soft-preview {
      font-family:
        "Avenir Next",
        "Trebuchet MS",
        sans-serif;
    }

    .font-journal-preview {
      font-family:
        Georgia,
        "Times New Roman",
        serif;
    }

    .settings-actions {
      display: grid;
      gap: 8px;
    }

    .modal-backdrop {
      display: none;
      position: fixed;
      inset: 0;
      z-index: 40;
      overflow-y: auto;
      background: rgba(58,58,62,.28);
      padding:
        calc(18px + env(safe-area-inset-top))
        16px
        calc(18px + env(safe-area-inset-bottom));
    }

    .modal-backdrop.open {
      display: block;
    }

    .modal {
      width: 100%;
      max-width: 580px;
      margin: 20px auto;
      border: 1px solid var(--border);
      border-radius: 20px;
      background: var(--card);
      padding: 18px;
    }

    .modal-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      margin-bottom: 15px;
    }

    .modal-header h2 {
      margin: 0;
      font-size: 20px;
    }

    .close-button {
      width: 42px;
      height: 42px;
      border: 0;
      border-radius: 50%;
      background: #f5f3f1;
      color: var(--text);
      font-size: 20px;
    }

    .modal-actions {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      margin-top: 15px;
    }

    .modal-actions > * {
      flex: 1 1 120px;
    }

    .toast {
      display: none;
      position: fixed;
      z-index: 60;
      left: 50%;
      bottom:
        calc(78px + env(safe-area-inset-bottom));
      transform: translateX(-50%);
      max-width: calc(100% - 32px);
      border-radius: 20px;
      background: #55545a;
      color: white;
      padding: 10px 15px;
      text-align: center;
      font-size: 13px;
    }

    .toast.show {
      display: block;
    }

    .loading {
      display: grid;
      place-items: center;
      min-height: 180px;
      color: var(--muted);
    }

    .counselor-summary {
      display: grid;
      gap: 0;
    }

    .summary-row {
      display: flex;
      justify-content: space-between;
      gap: 15px;
      padding: 10px 0;
      border-bottom: 1px solid var(--border);
    }

    .summary-row:last-child {
      border-bottom: 0;
    }

    .custom-dates {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 9px;
      margin-top: 10px;
    }

    @media (max-width: 420px) {
      .thought-truth {
        grid-template-columns: 1fr;
      }

      .stat-grid {
        grid-template-columns: 1fr;
      }

      .intensity-grid {
        gap: 3px;
      }

      .intensity-button {
        min-height: 40px;
        font-size: 13px;
      }

      .time-fields,
      .custom-dates {
        grid-template-columns: 1fr;
      }
    }

    @media print {
      body {
        background: white;
      }

      .topbar,
      .bottom-nav,
      .no-print,
      .pattern-nav,
      .range-nav {
        display: none !important;
      }

      .shell {
        max-width: none;
        padding: 0;
      }

      .page {
        display: none !important;
      }

      #patternsPage {
        display: block !important;
      }

      .card {
        break-inside: avoid;
        border: 1px solid #ddd;
      }
    }

    .remember-device { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
    .remember-device input { width: 20px; height: 20px; flex: 0 0 auto; accent-color: var(--accent); }
    .card:has(> label[for="thoughtInput"]),
    .card:has(> label[for="truthInput"]) { background: #e6dfd6; }
    label[for="thoughtInput"], label[for="truthInput"] { color: #414247; font-weight: 700; }
    .text-input, .text-area, .time-input,
    .intensity-button, .font-choice, .secondary-button { border-width: 1.5px; }
    .intensity-button:nth-child(1) { background: hsl(265 32% 94%); color: #303137; }
    .intensity-button:nth-child(2) { background: hsl(265 32% 91%); color: #303137; }
    .intensity-button:nth-child(3) { background: hsl(265 32% 88%); color: #303137; }
    .intensity-button:nth-child(4) { background: hsl(265 32% 85%); color: #303137; }
    .intensity-button:nth-child(5) { background: hsl(265 32% 82%); color: #303137; }
    .intensity-button:nth-child(6) { background: hsl(265 32% 79%); color: #303137; }
    .intensity-button:nth-child(7) { background: hsl(265 32% 76%); color: #303137; }
    .intensity-button:nth-child(8) { background: hsl(265 32% 73%); color: #303137; }
    .intensity-button:nth-child(9) { background: hsl(265 32% 70%); color: #303137; }
    .intensity-button:nth-child(10) { background: hsl(265 32% 67%); color: #303137; }
    .intensity-button.selected { border-color: #514061; box-shadow: inset 0 0 0 1px #514061; }
    .intensity-button:focus-visible { outline: 2px solid #514061; outline-offset: 2px; }
    .time-input { min-width: 0; }
    .timeline-axis { gap: 8px; }
    .day-hour { position: absolute; top: 2px; transform: translateX(-50%); font-size: 9px; color: #68686e; }
    .time-segment { text-align: center; font-size: 10px; overflow: hidden; line-height: 18px; }
    .type-button.selected { border-color: var(--accent); }
    .primary-button { color: #303137; }
    .ongoing-card > div { min-width: 0; }
    @media (max-width: 420px) {
      .intensity-grid { grid-template-columns: repeat(5, 1fr); gap: 6px; }
      .intensity-button { min-height: 44px; }
    }
    @media print {
      #overviewPattern, #timePattern, #intensityPattern, .modal-backdrop, .toast { display: none !important; }
      #counselorPattern { display: block !important; }
      .entry-card { break-inside: auto; }
    }
