:root {
      color-scheme: dark;
      --bg: #efe6d7;
      --panel: rgba(255, 252, 245, 0.6);
      --panel-soft: rgba(255, 255, 255, 0.38);
      --line: rgba(41, 38, 32, 0.12);
      --line-strong: rgba(41, 38, 32, 0.24);
      --paper: #292620;
      --fog: #5e574e;
      --muted: rgba(41, 38, 32, 0.62);
      --quiet: rgba(41, 38, 32, 0.42);
      --walnut: #d7cbb8;
      --clay: #9b8f7f;
      --font-main: "Helvetica Neue Bold", "Helvetica Neue", Helvetica, Arial, sans-serif;
    }

    * {
      box-sizing: border-box;
    }

    body {
      min-height: 100vh;
      margin: 0;
      overflow-x: hidden;
      background:
        radial-gradient(circle at 18% 10%, rgba(255, 255, 255, 0.62), transparent 28rem),
        radial-gradient(circle at 76% 18%, rgba(213, 200, 180, 0.52), transparent 26rem),
        linear-gradient(142deg, #f5eee2 0%, #ebe0cf 48%, #f8f2e9 100%);
      color: var(--paper);
      font-family: var(--font-main);
      font-weight: 700;
      letter-spacing: 0;
    }

    body::before,
    body::after {
      content: "";
      position: fixed;
      inset: 0;
      pointer-events: none;
    }

    body::before {
      z-index: -4;
      background-image:
        linear-gradient(rgba(41, 38, 32, 0.045) 1px, transparent 1px),
        linear-gradient(90deg, rgba(41, 38, 32, 0.035) 1px, transparent 1px);
      background-size: 86px 86px;
      mask-image: linear-gradient(to bottom, transparent 0%, black 16%, black 86%, transparent 100%);
    }

    body::after {
      z-index: -1;
      opacity: 0.1;
      background-image:
        url("data:image/svg+xml,%3Csvg viewBox='0 0 220 220' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
      mix-blend-mode: multiply;
    }

    #lofiCanvas {
      position: fixed;
      inset: 0;
      z-index: -3;
      width: 100vw;
      height: 100vh;
      opacity: 0.78;
      pointer-events: none;
      filter: blur(0.25px);
    }

    .soft-vignette {
      position: fixed;
      inset: 0;
      z-index: -2;
      pointer-events: none;
      background:
        radial-gradient(circle at var(--mx, 50%) var(--my, 50%), rgba(255, 255, 255, 0.62), transparent 17rem),
        radial-gradient(circle at center, transparent 0 54%, rgba(70, 58, 42, 0.13) 100%);
      transition: background 180ms ease;
    }

    .app {
      display: flex;
      flex-direction: column;
      min-height: 100vh;
      padding: 22px;
    }

    main {
      flex: 1 0 auto;
    }

    .topbar {
      position: sticky;
      top: 16px;
      z-index: 50;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 16px;
      width: min(100%, 520px);
      max-width: 520px;
      margin: 0 auto;
      border: 1px solid rgba(255, 255, 255, 0.48);
      background: rgba(255, 255, 255, 0.34);
      backdrop-filter: blur(22px);
      border-radius: 12px;
      padding: 10px;
      box-shadow: 0 22px 70px rgba(78, 67, 50, 0.14), inset 0 1px 0 rgba(255,255,255,0.72);
      overflow: hidden;
      transition: transform 220ms ease, box-shadow 220ms ease, background 220ms ease;
    }

    .topbar::before {
      content: "";
      position: absolute;
      inset: -60% -12%;
      background:
        radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.72), transparent 18%),
        linear-gradient(115deg, transparent 34%, rgba(255, 255, 255, 0.34) 48%, transparent 62%);
      opacity: 0.42;
      transform: translateX(-18%) rotate(8deg);
      transition: opacity 240ms ease, transform 420ms cubic-bezier(.22,.8,.22,1);
      pointer-events: none;
    }

    .topbar:hover {
      transform: translateY(-1px);
      background: rgba(255, 255, 255, 0.42);
      box-shadow: 0 24px 76px rgba(78, 67, 50, 0.17), inset 0 1px 0 rgba(255,255,255,0.8);
    }

    .topbar:hover::before {
      opacity: 0.68;
      transform: translateX(14%) rotate(8deg);
    }

    .brand {
      position: relative;
      z-index: 1;
      display: inline-flex;
      align-items: center;
      gap: 10px;
      width: fit-content;
      border: 0;
      background: transparent;
      color: var(--paper);
      cursor: pointer;
    }

    .brand-mark {
      display: grid;
      place-items: center;
      width: 32px;
      height: 32px;
      border: 1px solid rgba(255, 255, 255, 0.5);
      border-radius: 999px;
      color: var(--fog);
      background: rgba(255, 255, 255, 0.34);
    }

    .brand-text {
      font-family: var(--font-main);
      font-size: 17px;
      font-weight: 700;
      letter-spacing: 0;
    }

    .nav {
      position: relative;
      z-index: 1;
      display: grid;
      width: 100%;
      grid-template-columns: repeat(3, minmax(82px, 1fr));
      gap: 4px;
      border: 1px solid rgba(255, 255, 255, 0.42);
      background: rgba(255, 255, 255, 0.26);
      border-radius: 999px;
      padding: 4px;
      backdrop-filter: blur(18px) saturate(1.15);
      box-shadow: inset 0 1px 0 rgba(255,255,255,0.64), 0 10px 28px rgba(82, 69, 52, 0.08);
    }

    .nav-indicator {
      position: absolute;
      top: 4px;
      bottom: 4px;
      left: 4px;
      width: calc((100% - 8px) / 3);
      border-radius: 999px;
      background: rgba(255, 255, 255, 0.58);
      box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.82), 0 8px 22px rgba(77, 67, 54, 0.1);
      transition: transform 320ms cubic-bezier(.22,.8,.22,1);
    }

    .nav[data-active="search"] .nav-indicator {
      transform: translateX(100%);
    }

    .nav[data-active="square"] .nav-indicator {
      transform: translateX(200%);
    }

    .nav-button {
      position: relative;
      z-index: 1;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 7px;
      min-height: 36px;
      border: 0;
      background: transparent;
      color: rgba(41, 38, 32, 0.52);
      border-radius: 999px;
      font-size: 13px;
      font-weight: 700;
      cursor: pointer;
      transition: color 180ms ease, transform 180ms ease;
    }

    .nav-button:hover {
      transform: translateY(-1px);
    }

    .nav-button:hover,
    .nav-button.active {
      color: var(--paper);
    }

    .history-button,
    .icon-button,
    .primary-button,
    .ghost-button {
      position: relative;
      z-index: 1;
      overflow: hidden;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      border-radius: 999px;
      cursor: pointer;
      backdrop-filter: blur(16px) saturate(1.16);
      box-shadow: inset 0 1px 0 rgba(255,255,255,0.68), 0 10px 24px rgba(83, 70, 53, 0.08);
      transition: transform 180ms ease, border-color 180ms ease, background 180ms ease, color 180ms ease, opacity 180ms ease, box-shadow 180ms ease;
    }

    .history-button::before,
    .icon-button::before,
    .primary-button::before,
    .ghost-button::before {
      content: "";
      position: absolute;
      inset: -90% -45%;
      background: linear-gradient(115deg, transparent 38%, rgba(255,255,255,0.68) 50%, transparent 62%);
      opacity: 0;
      transform: translateX(-38%) rotate(8deg);
      transition: opacity 180ms ease, transform 420ms cubic-bezier(.22,.8,.22,1);
      pointer-events: none;
    }

    .history-button:hover::before,
    .icon-button:hover::before,
    .primary-button:hover::before,
    .ghost-button:hover::before {
      opacity: 0.65;
      transform: translateX(38%) rotate(8deg);
    }

    .history-button {
      justify-self: end;
      min-height: 38px;
      border: 1px solid var(--line);
      background: rgba(255, 255, 255, 0.36);
      color: var(--muted);
      padding: 0 13px;
      font-size: 13px;
      font-weight: 700;
    }

    .history-button:hover,
    .icon-button:hover,
    .ghost-button:hover {
      border-color: var(--line-strong);
      background: rgba(255, 255, 255, 0.54);
      color: var(--paper);
      transform: translateY(-1px);
      box-shadow: inset 0 1px 0 rgba(255,255,255,0.78), 0 14px 32px rgba(83, 70, 53, 0.12);
    }

    .icon-button {
      width: 38px;
      height: 38px;
      border: 1px solid var(--line);
      background: rgba(255, 255, 255, 0.36);
      color: var(--muted);
    }

    .primary-button {
      min-height: 46px;
      border: 1px solid rgba(255, 255, 255, 0.58);
      background: rgba(255, 255, 255, 0.5);
      color: var(--paper);
      padding: 0 18px;
      font-size: 14px;
      font-weight: 700;
      box-shadow: 0 14px 36px rgba(91, 75, 56, 0.14), inset 0 1px 0 rgba(255,255,255,0.78);
    }

    .primary-button:hover {
      background: rgba(255, 255, 255, 0.68);
      transform: translateY(-1px);
      box-shadow: inset 0 1px 0 rgba(255,255,255,0.84), 0 18px 38px rgba(83, 70, 53, 0.14);
    }

    .ghost-button {
      min-height: 42px;
      border: 1px solid var(--line);
      background: rgba(255, 255, 255, 0.36);
      color: var(--muted);
      padding: 0 13px;
      font-size: 13px;
      font-weight: 700;
    }

    .view {
      display: none;
      min-height: calc(100vh - 150px);
      max-width: 1060px;
      margin: 0 auto;
      padding: 46px 0 26px;
      animation: viewIn 420ms cubic-bezier(.22,.8,.22,1) both;
    }

    .view.active {
      display: grid;
      align-items: center;
    }

    .view.square-view.active {
      align-items: start;
    }

    #journalView.view.active {
      align-items: start;
      padding-top: clamp(76px, 10vh, 96px);
    }

    @keyframes viewIn {
      from {
        opacity: 0;
        transform: translateY(12px);
        filter: blur(8px);
      }
      to {
        opacity: 1;
        transform: translateY(0);
        filter: blur(0);
      }
    }

    .panel {
      border: 1px solid var(--line);
      background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.46), rgba(255, 255, 255, 0.2)),
        var(--panel);
      backdrop-filter: blur(24px);
      border-radius: 8px;
      box-shadow: 0 24px 70px rgba(91, 75, 56, 0.13), inset 0 1px 0 rgba(255,255,255,0.68);
      transition: transform 220ms ease, box-shadow 220ms ease, border-color 220ms ease, background 220ms ease;
    }

    .panel:hover {
      transform: translateY(-2px);
      border-color: var(--line-strong);
      box-shadow: 0 28px 80px rgba(91, 75, 56, 0.16), inset 0 1px 0 rgba(255,255,255,0.74);
    }

    .journal-wrap {
      display: grid;
      justify-items: stretch;
      width: min(720px, 100%);
      margin: 0 auto;
      gap: 14px;
    }

    .journal-heading {
      display: grid;
      justify-items: start;
      gap: 7px;
      margin-bottom: 4px;
      text-align: left;
    }

    .quiet-title {
      margin: 0;
      color: var(--paper);
      font-family: var(--font-main);
      font-size: 48px;
      line-height: 1.2;
      font-weight: 700;
      letter-spacing: 0;
      text-align: left;
    }

    .journal-subtitle {
      margin: 0;
      color: var(--quiet);
      font-size: 13px;
      font-weight: 700;
      line-height: 1.6;
      text-align: left;
    }

    .site-footer {
      flex: 0 0 auto;
      display: flex;
      align-items: center;
      justify-content: center;
      min-height: 24px;
      color: var(--quiet);
      font-size: 11px;
      font-weight: 700;
      line-height: 1;
      text-align: center;
    }

    .journal-card {
      position: relative;
      isolation: isolate;
      width: min(720px, 100%);
      padding: 22px;
      overflow: visible;
      transform-origin: 52% 8%;
      background:
        linear-gradient(180deg, rgba(255, 253, 239, 0.86), rgba(239, 229, 205, 0.74)),
        var(--panel);
      border-color: rgba(82, 73, 58, 0.13);
      box-shadow:
        0 26px 54px rgba(101, 82, 55, 0.16),
        0 3px 0 rgba(145, 129, 102, 0.06),
        inset 0 1px 0 rgba(255,255,255,0.84);
    }

    .journal-card:hover:not(.tearing) {
      transform: translateY(-3px) rotate(-0.15deg);
    }

    .journal-card::before {
      content: "";
      position: absolute;
      top: -14px;
      left: 50%;
      z-index: 2;
      width: 132px;
      height: 27px;
      border: 1px solid rgba(255, 255, 255, 0.5);
      background: rgba(255, 255, 255, 0.42);
      backdrop-filter: blur(10px);
      border-radius: 4px;
      box-shadow: 0 10px 24px rgba(94, 76, 52, 0.1);
      transform: translateX(-50%) rotate(-1.2deg);
    }

    .journal-card::after {
      content: "";
      position: absolute;
      left: 12px;
      right: 12px;
      bottom: -9px;
      height: 14px;
      opacity: 0.72;
      background:
        linear-gradient(135deg, transparent 8px, rgba(239, 229, 205, 0.74) 0) left top / 18px 14px repeat-x,
        linear-gradient(225deg, transparent 8px, rgba(239, 229, 205, 0.74) 0) left top / 18px 14px repeat-x;
      filter: drop-shadow(0 10px 10px rgba(101, 82, 55, 0.08));
      pointer-events: none;
    }

    .journal-card.tearing {
      animation: tearAway 820ms cubic-bezier(.28,.74,.26,1) forwards;
      pointer-events: none;
    }

    .journal-card.tearing::after {
      animation: tearEdge 820ms ease forwards;
    }

    .journal-card.fresh-note {
      animation: freshNote 460ms cubic-bezier(.22,.8,.22,1) both;
    }

    @keyframes tearAway {
      0% {
        opacity: 1;
        transform: translateY(0) rotate(0deg);
        filter: blur(0);
      }
      34% {
        transform: translateY(-8px) rotate(-1.4deg);
      }
      62% {
        opacity: 0.96;
        transform: translate(18px, -42px) rotate(4deg);
        filter: blur(0.4px);
      }
      100% {
        opacity: 0;
        transform: translate(76px, -170px) rotate(10deg) scale(0.94);
        filter: blur(5px);
      }
    }

    @keyframes tearEdge {
      0% {
        transform: translateY(0);
        opacity: 0.72;
      }
      42% {
        transform: translateY(7px) skewX(-8deg);
        opacity: 0.92;
      }
      100% {
        transform: translateY(16px) skewX(-14deg);
        opacity: 0;
      }
    }

    @keyframes freshNote {
      from {
        opacity: 0;
        transform: translateY(18px) rotate(-0.8deg) scale(0.985);
        filter: blur(5px);
      }
      to {
        opacity: 1;
        transform: translateY(0) rotate(0deg) scale(1);
        filter: blur(0);
      }
    }

    .field-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      margin-bottom: 11px;
      color: var(--muted);
      font-size: 13px;
      font-weight: 700;
    }

    .note-count {
      position: absolute;
      top: 25px;
      right: 25px;
      z-index: 3;
      min-width: 28px;
      color: rgba(41, 38, 32, 0.48);
      font-size: 13px;
      font-weight: 700;
      text-align: right;
      pointer-events: none;
    }

    .text-field {
      width: 100%;
      border: 1px solid rgba(41, 38, 32, 0.13);
      background: rgba(255, 255, 255, 0.38);
      border-radius: 8px;
      color: var(--paper);
      outline: none;
      resize: none;
      line-height: 1.75;
      transition: border-color 180ms ease, background 180ms ease, box-shadow 180ms ease, transform 180ms ease;
    }

    .text-field:focus {
      border-color: rgba(41, 38, 32, 0.26);
      background: rgba(255, 255, 255, 0.54);
      box-shadow: 0 0 0 5px rgba(41, 38, 32, 0.045);
      transform: translateY(-1px);
    }

    .text-field:hover {
      border-color: rgba(41, 38, 32, 0.2);
      box-shadow: inset 0 1px 0 rgba(255,255,255,0.54), 0 10px 28px rgba(91, 75, 56, 0.08);
    }

    .text-field::placeholder {
      color: rgba(41, 38, 32, 0.34);
    }

    .dream-input {
      min-height: 300px;
      padding: 24px 19px 18px;
      font-size: 16px;
      line-height: 32px;
      border-color: rgba(82, 73, 58, 0.1);
      background:
        linear-gradient(
          to bottom,
          transparent 0,
          transparent 30px,
          rgba(82, 73, 58, 0.12) 31px,
          transparent 32px
        ),
        rgba(255, 251, 238, 0.36);
      background-size: 100% 32px, auto;
      background-position: 0 19px, 0 0;
      background-repeat: repeat, no-repeat;
      box-shadow: inset 0 1px 0 rgba(255,255,255,0.5);
    }

    .dream-input:focus {
      background:
        linear-gradient(
          to bottom,
          transparent 0,
          transparent 30px,
          rgba(82, 73, 58, 0.14) 31px,
          transparent 32px
        ),
        rgba(255, 251, 238, 0.5);
      background-size: 100% 32px, auto;
      background-position: 0 19px, 0 0;
      background-repeat: repeat, no-repeat;
    }

    .scene-input {
      min-height: 168px;
      padding: 16px;
      font-size: 15px;
    }

    .journal-actions {
      display: flex;
      align-items: center;
      justify-content: flex-start;
      gap: 12px;
      margin-top: 15px;
    }

    .action-left {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 9px;
      width: 100%;
      flex-wrap: nowrap;
    }

    .publish-bar {
      position: relative;
      display: flex;
      width: 100%;
      transition: transform 220ms ease, opacity 220ms ease;
    }

    .publish-button {
      position: relative;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      width: 100%;
      min-height: 52px;
      border: 1px solid rgba(255, 255, 255, 0.72);
      border-radius: 12px;
      background: rgba(255, 255, 255, 0.46);
      -webkit-backdrop-filter: blur(22px) saturate(1.14);
      backdrop-filter: blur(22px) saturate(1.14);
      color: var(--paper);
      font-family: var(--font-main);
      font-size: 13px;
      font-weight: 700;
      cursor: pointer;
      box-shadow: inset 0 1px 0 rgba(255,255,255,0.9), inset 0 -1px 0 rgba(95, 79, 58, 0.05), 0 16px 38px rgba(82, 69, 52, 0.12);
      transition: transform 180ms ease, border-color 180ms ease, background 180ms ease, box-shadow 180ms ease;
    }

    .publish-button:hover {
      transform: translateY(-1px);
      border-color: rgba(255, 255, 255, 0.9);
      background: rgba(255, 255, 255, 0.58);
      box-shadow: inset 0 1px 0 rgba(255,255,255,0.96), inset 0 -1px 0 rgba(95, 79, 58, 0.06), 0 20px 44px rgba(82, 69, 52, 0.15);
    }

    .publish-button:active {
      transform: translateY(0) scale(0.995);
    }

    .journal-card.tearing + .publish-bar {
      opacity: 0.58;
      pointer-events: none;
      transform: translateY(2px) scale(0.995);
    }

    .emotion-picker {
      position: relative;
    }

    .emotion-orb {
      position: relative;
      display: inline-grid;
      place-items: center;
      width: 46px;
      height: 46px;
      border: 1px solid rgba(255,255,255,0.62);
      border-radius: 999px;
      background:
        radial-gradient(circle at 30% 24%, rgba(255,255,255,0.84), rgba(255,255,255,0.26) 54%, rgba(255,255,255,0.42) 100%);
      color: var(--fog);
      box-shadow: inset 0 1px 1px rgba(255,255,255,0.9), inset 0 -10px 20px rgba(111, 94, 70, 0.08), 0 12px 28px rgba(83, 70, 53, 0.1);
      backdrop-filter: blur(16px) saturate(1.2);
      cursor: pointer;
      transition: transform 190ms ease, box-shadow 190ms ease, color 190ms ease;
    }

    .emotion-orb::after {
      content: "";
      position: absolute;
      top: 9px;
      left: 12px;
      width: 11px;
      height: 7px;
      border-radius: 999px;
      background: rgba(255,255,255,0.78);
      transform: rotate(-24deg);
      pointer-events: none;
    }

    .emotion-orb:hover,
    .emotion-orb[aria-expanded="true"] {
      color: var(--paper);
      transform: translateY(-2px) scale(1.04);
      box-shadow: inset 0 1px 1px rgba(255,255,255,0.92), inset 0 -10px 20px rgba(111, 94, 70, 0.09), 0 16px 34px rgba(83, 70, 53, 0.15);
    }

    .emotion-menu {
      position: absolute;
      left: 0;
      bottom: calc(100% + 8px);
      z-index: 40;
      display: grid;
      width: 224px;
      max-width: calc(100vw - 44px);
      gap: 7px;
      border: 1px solid rgba(255,255,255,0.58);
      background: rgba(255, 252, 245, 0.72);
      backdrop-filter: blur(22px) saturate(1.18);
      border-radius: 8px;
      padding: 8px;
      box-shadow: 0 18px 54px rgba(91, 75, 56, 0.16), inset 0 1px 0 rgba(255,255,255,0.72);
      transform: translateY(8px) scale(0.98);
      transform-origin: bottom left;
      opacity: 0;
      pointer-events: none;
      transition: opacity 160ms ease, transform 160ms ease;
    }

    .emotion-menu-head {
      padding: 4px 8px 1px;
      color: var(--quiet);
      font-size: 11px;
      font-weight: 700;
    }

    .emotion-list {
      display: grid;
      gap: 4px;
      max-height: 176px;
      overflow: auto;
      padding-right: 2px;
    }

    .emotion-list::-webkit-scrollbar {
      width: 6px;
    }

    .emotion-list::-webkit-scrollbar-thumb {
      background: rgba(41, 38, 32, 0.14);
      border-radius: 999px;
    }

    .emotion-menu.open {
      opacity: 1;
      pointer-events: auto;
      transform: translateY(0) scale(1);
    }

    .emotion-item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
      min-height: 36px;
      border: 0;
      background: transparent;
      color: var(--muted);
      border-radius: 8px;
      padding: 0 10px;
      font-size: 13px;
      cursor: pointer;
      transition: background 160ms ease, color 160ms ease;
    }

    .emotion-item > span {
      display: inline-flex;
      min-width: 0;
      align-items: center;
      white-space: nowrap;
    }

    .emotion-item > i {
      flex: 0 0 auto;
    }

    .emotion-item:hover,
    .emotion-item.active {
      background: rgba(41, 38, 32, 0.06);
      color: var(--paper);
    }

    .custom-tag-row {
      display: grid;
      grid-template-columns: minmax(0, 1fr) 36px;
      gap: 6px;
      border-top: 1px solid rgba(41, 38, 32, 0.08);
      padding-top: 7px;
    }

    .custom-tag-input {
      min-width: 0;
      height: 36px;
      border: 1px solid rgba(41, 38, 32, 0.11);
      border-radius: 999px;
      background: rgba(255, 255, 255, 0.42);
      color: var(--paper);
      outline: none;
      padding: 0 12px;
      font-size: 13px;
    }

    .custom-tag-input:focus {
      border-color: rgba(41, 38, 32, 0.24);
      background: rgba(255, 255, 255, 0.58);
    }

    .custom-tag-button {
      display: inline-grid;
      place-items: center;
      width: 36px;
      height: 36px;
      border: 1px solid rgba(255,255,255,0.58);
      border-radius: 999px;
      background: rgba(255, 255, 255, 0.46);
      color: var(--fog);
      cursor: pointer;
      transition: transform 160ms ease, background 160ms ease, color 160ms ease;
    }

    .custom-tag-button:hover {
      transform: translateY(-1px);
      background: rgba(255, 255, 255, 0.68);
      color: var(--paper);
    }

    .switch {
      display: inline-flex;
      align-items: center;
      gap: 9px;
      min-height: 42px;
      border: 1px solid var(--line);
      background: rgba(255, 255, 255, 0.36);
      border-radius: 999px;
      color: var(--muted);
      padding: 0 11px;
      font-size: 13px;
      cursor: pointer;
      user-select: none;
      transition: border-color 180ms ease, background 180ms ease, color 180ms ease;
    }

    .switch:hover {
      border-color: var(--line-strong);
      color: var(--paper);
    }

    .switch-track {
      position: relative;
      width: 38px;
      height: 22px;
      border: 1px solid rgba(41, 38, 32, 0.16);
      background: rgba(41, 38, 32, 0.08);
      border-radius: 999px;
      transition: background 180ms ease, border-color 180ms ease;
    }

    .switch-dot {
      position: absolute;
      top: 3px;
      left: 3px;
      width: 14px;
      height: 14px;
      border-radius: 999px;
      background: rgba(41, 38, 32, 0.42);
      transition: transform 180ms ease, background 180ms ease;
    }

    #publicSwitch:checked + .switch-track {
      border-color: rgba(41, 38, 32, 0.22);
      background: rgba(41, 38, 32, 0.13);
    }

    #publicSwitch:checked + .switch-track .switch-dot {
      transform: translateX(16px);
      background: var(--paper);
    }

    .search-layout {
      display: grid;
      grid-template-columns: minmax(320px, 0.72fr) minmax(0, 1fr);
      gap: 20px;
      align-items: center;
    }

    .search-card {
      padding: 22px;
    }

    .section-label {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      color: var(--quiet);
      font-size: 12px;
      font-weight: 700;
    }

    .section-title {
      margin: 10px 0 0;
      color: var(--paper);
      font-family: var(--font-main);
      font-size: clamp(26px, 4vw, 40px);
      font-weight: 700;
      letter-spacing: 0;
    }

    .section-subtitle {
      max-width: 420px;
      margin: 8px 0 0;
      color: var(--quiet);
      font-size: 13px;
      font-weight: 700;
      line-height: 1.7;
    }

    .quick-row {
      display: flex;
      flex-wrap: wrap;
      gap: 7px;
      margin-top: 12px;
    }

    .quick-chip,
    .filter-chip {
      min-height: 34px;
      border: 1px solid var(--line);
      background: rgba(255, 255, 255, 0.34);
      color: var(--muted);
      border-radius: 999px;
      padding: 0 11px;
      font-size: 12px;
      font-weight: 700;
      cursor: pointer;
      transition: transform 170ms ease, border-color 170ms ease, background 170ms ease, color 170ms ease;
    }

    .quick-chip:hover,
    .filter-chip:hover,
    .filter-chip.active {
      transform: translateY(-1px);
      border-color: var(--line-strong);
      background: rgba(255, 255, 255, 0.54);
      color: var(--paper);
    }

    .result-stack {
      display: grid;
      gap: 10px;
    }

    .result-card,
    .dream-card {
      position: relative;
      overflow: hidden;
      border: 1px solid var(--line);
      background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.18)),
        rgba(255, 252, 245, 0.54);
      backdrop-filter: blur(18px);
      border-radius: 8px;
      transition: transform 220ms cubic-bezier(.22,.8,.22,1), border-color 220ms ease, background 220ms ease, box-shadow 220ms ease;
    }

    .result-card::before,
    .dream-card::before {
      content: "";
      position: absolute;
      inset: 0;
      opacity: 0;
      background: radial-gradient(circle at var(--card-x, 50%) var(--card-y, 20%), rgba(255, 255, 255, 0.55), transparent 12rem);
      transition: opacity 220ms ease;
      pointer-events: none;
    }

    .result-card:hover,
    .dream-card:hover,
    .dream-card:focus-visible {
      transform: translateY(-4px);
      border-color: var(--line-strong);
      box-shadow: 0 18px 54px rgba(91, 75, 56, 0.13);
      outline: none;
    }

    .result-card:hover::before,
    .dream-card:hover::before,
    .dream-card:focus-visible::before {
      opacity: 1;
    }

    .result-card {
      display: grid;
      grid-template-columns: 76px minmax(0, 1fr);
      gap: 15px;
      padding: 14px;
      cursor: pointer;
    }

    .score {
      display: grid;
      align-content: center;
      justify-items: center;
      width: 66px;
      height: 66px;
      border: 1px solid rgba(41, 38, 32, 0.14);
      border-radius: 8px;
      background: rgba(255, 255, 255, 0.42);
    }

    .score strong {
      color: var(--paper);
      font-size: 18px;
      line-height: 1;
    }

    .score span {
      margin-top: 4px;
      color: var(--quiet);
      font-size: 10px;
    }

    .match-bar {
      grid-column: 1 / -1;
      height: 4px;
      overflow: hidden;
      border-radius: 999px;
      background: rgba(41, 38, 32, 0.08);
    }

    .match-fill {
      height: 100%;
      width: var(--score-width);
      border-radius: inherit;
      background: rgba(41, 38, 32, 0.54);
      transition: width 500ms cubic-bezier(.22,.8,.22,1);
    }

    .meta-row {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 8px;
      margin-bottom: 8px;
    }

    .emotion-badge {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      min-height: 25px;
      border: 1px solid rgba(41, 38, 32, 0.12);
      background: rgba(255, 255, 255, 0.34);
      border-radius: 999px;
      color: var(--fog);
      padding: 0 9px;
      font-size: 12px;
      font-weight: 700;
    }

    .card-text {
      position: relative;
      display: -webkit-box;
      -webkit-line-clamp: 3;
      -webkit-box-orient: vertical;
      overflow: hidden;
      color: rgba(41, 38, 32, 0.72);
      font-size: 14px;
      line-height: 1.76;
    }

    .keyword-row {
      position: relative;
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
      margin-top: 10px;
    }

    .keyword {
      border: 1px solid rgba(41, 38, 32, 0.1);
      background: rgba(255, 255, 255, 0.32);
      border-radius: 999px;
      color: var(--quiet);
      padding: 4px 8px;
      font-size: 11px;
    }

    .empty-state {
      display: grid;
      place-items: center;
      min-height: 260px;
      border: 1px dashed rgba(41, 38, 32, 0.14);
      background: rgba(255, 255, 255, 0.28);
      border-radius: 8px;
      color: var(--quiet);
      text-align: center;
      padding: 28px;
      font-size: 14px;
      line-height: 1.7;
    }

    .square-head {
      display: flex;
      align-items: end;
      justify-content: space-between;
      gap: 18px;
      margin-bottom: 18px;
    }

    .filter-row {
      display: flex;
      flex-wrap: wrap;
      justify-content: flex-end;
      gap: 7px;
    }

    .square-controls {
      display: grid;
      justify-items: end;
      gap: 8px;
    }

    .mode-row {
      display: flex;
      flex-wrap: wrap;
      justify-content: flex-end;
      gap: 7px;
    }

    .square-grid {
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 12px;
    }

    .dream-card {
      min-height: 204px;
      padding: 15px;
      cursor: pointer;
    }

    .dream-card .card-text {
      margin-top: 17px;
      -webkit-line-clamp: 5;
    }

    .drawer-backdrop {
      position: fixed;
      inset: 0;
      z-index: 70;
      display: none;
      background: rgba(58, 48, 35, 0.16);
      backdrop-filter: blur(6px);
    }

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

    .drawer {
      position: fixed;
      top: 0;
      right: 0;
      z-index: 80;
      width: min(410px, calc(100vw - 20px));
      height: 100vh;
      border-left: 1px solid var(--line);
      background: rgba(255, 252, 245, 0.72);
      backdrop-filter: blur(28px);
      transform: translateX(105%);
      transition: transform 300ms cubic-bezier(.22,.8,.22,1);
      padding: 18px;
      box-shadow: -28px 0 80px rgba(91, 75, 56, 0.16);
    }

    .drawer.open {
      transform: translateX(0);
    }

    .drawer-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      margin-bottom: 14px;
    }

    .history-list {
      display: grid;
      gap: 10px;
      max-height: calc(100vh - 88px);
      overflow: auto;
      padding-right: 3px;
    }

    .history-list::-webkit-scrollbar {
      width: 8px;
    }

    .history-list::-webkit-scrollbar-thumb {
      background: rgba(41, 38, 32, 0.16);
      border-radius: 999px;
    }

    .modal {
      position: fixed;
      inset: 0;
      z-index: 100;
      display: none;
      place-items: center;
      padding: 18px;
      background: rgba(58, 48, 35, 0.16);
      backdrop-filter: blur(7px);
    }

    .modal.open {
      display: grid;
    }

    .modal-card {
      width: min(620px, 100%);
      border: 1px solid var(--line);
      background: rgba(255, 252, 245, 0.78);
      backdrop-filter: blur(28px);
      border-radius: 8px;
      padding: 18px;
      box-shadow: 0 30px 90px rgba(91, 75, 56, 0.18);
      animation: modalIn 220ms ease both;
    }

    @keyframes modalIn {
      from {
        opacity: 0;
        transform: translateY(10px) scale(0.985);
      }
      to {
        opacity: 1;
        transform: translateY(0) scale(1);
      }
    }

    .toast {
      position: fixed;
      left: 50%;
      bottom: 22px;
      z-index: 110;
      display: inline-flex;
      align-items: center;
      gap: 8px;
      min-height: 42px;
      border: 1px solid var(--line-strong);
      background: rgba(255, 252, 245, 0.76);
      backdrop-filter: blur(20px);
      color: var(--paper);
      border-radius: 999px;
      padding: 0 15px;
      font-size: 13px;
      transform: translate(-50%, 16px);
      opacity: 0;
      pointer-events: none;
      transition: opacity 180ms ease, transform 180ms ease;
    }

    .toast.show {
      opacity: 1;
      transform: translate(-50%, 0);
    }

    .account-bubble {
      position: fixed;
      right: 22px;
      bottom: 22px;
      z-index: 115;
      display: inline-flex;
      align-items: center;
      gap: 8px;
      min-height: 42px;
      border: 1px solid rgba(255, 255, 255, 0.62);
      border-radius: 999px;
      background: rgba(255, 255, 255, 0.46);
      backdrop-filter: blur(22px) saturate(1.12);
      box-shadow: inset 0 1px 0 rgba(255,255,255,0.86), 0 14px 34px rgba(82, 69, 52, 0.12);
      color: var(--paper);
      padding: 0 14px;
      font-size: 13px;
      font-weight: 700;
      cursor: pointer;
      transition: transform 180ms ease, background 180ms ease, box-shadow 180ms ease;
    }

    .account-bubble:hover {
      transform: translateY(-1px);
      background: rgba(255, 255, 255, 0.62);
      box-shadow: inset 0 1px 0 rgba(255,255,255,0.92), 0 18px 40px rgba(82, 69, 52, 0.14);
    }

    .auth-modal {
      position: fixed;
      inset: 0;
      z-index: 130;
      display: none;
      align-items: center;
      justify-content: center;
      padding: 18px;
      background: rgba(58, 48, 35, 0.22);
      backdrop-filter: blur(8px);
    }

    .auth-modal.open {
      display: flex;
    }

    .auth-card {
      position: relative;
      width: min(440px, 100%);
      border: 1px solid rgba(255, 255, 255, 0.58);
      border-radius: 10px;
      background: rgba(255, 252, 245, 0.84);
      backdrop-filter: blur(24px) saturate(1.08);
      box-shadow: 0 30px 90px rgba(91, 75, 56, 0.2), inset 0 1px 0 rgba(255,255,255,0.8);
      padding: 22px;
    }

    .auth-close {
      position: absolute;
      top: 14px;
      right: 14px;
    }

    .auth-panel {
      display: grid;
      gap: 12px;
    }

    .auth-title {
      margin: 0;
      color: var(--paper);
      font-family: var(--font-main);
      font-size: clamp(24px, 3vw, 34px);
      line-height: 1.15;
      font-weight: 700;
      letter-spacing: 0;
    }

    .auth-copy {
      margin: 0;
      color: var(--quiet);
      font-size: 13px;
      font-weight: 700;
      line-height: 1.7;
    }

    .auth-form {
      display: grid;
      gap: 10px;
      margin-top: 2px;
    }

    .auth-input {
      width: 100%;
      min-height: 46px;
      border: 1px solid rgba(41, 38, 32, 0.13);
      border-radius: 8px;
      background: rgba(255, 255, 255, 0.48);
      color: var(--paper);
      outline: none;
      padding: 0 14px;
      font-size: 14px;
      font-weight: 700;
      transition: border-color 180ms ease, background 180ms ease, box-shadow 180ms ease;
    }

    .auth-input:focus {
      border-color: rgba(41, 38, 32, 0.24);
      background: rgba(255, 255, 255, 0.62);
      box-shadow: 0 0 0 5px rgba(41, 38, 32, 0.045);
    }

    .auth-message {
      margin: 0;
      min-height: 20px;
      color: var(--quiet);
      font-size: 12px;
      line-height: 1.6;
    }

    .auth-message.error {
      color: #7d4b41;
    }

    .setup-code {
      display: inline-flex;
      align-self: start;
      border: 1px solid rgba(41, 38, 32, 0.12);
      border-radius: 8px;
      background: rgba(255, 255, 255, 0.48);
      color: var(--paper);
      padding: 6px 10px;
      font-size: 12px;
      font-weight: 700;
    }

    @media (max-width: 900px) {
      .topbar {
        width: min(100%, 520px);
      }

      .search-layout {
        grid-template-columns: 1fr;
        align-items: start;
      }

      .square-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
      }
    }

    @media (max-width: 640px) {
      .app {
        padding: 14px;
      }

      .topbar {
        top: 10px;
      }

      .nav-button span,
      .history-button span {
        display: none;
      }

      .journal-card,
      .search-card {
        padding: 16px;
      }

      #journalView.view.active {
        padding-top: 78px;
      }

      .quiet-title {
        margin: 0;
        font-size: 42px;
      }

      .journal-subtitle {
        max-width: 330px;
        padding: 0;
        font-size: 12px;
      }

      .journal-actions {
        align-items: center;
      }

      .action-left {
        display: flex;
        justify-content: space-between;
        flex-wrap: nowrap;
        width: 100%;
      }

      .primary-button,
      .ghost-button {
        width: 100%;
      }

      .switch {
        width: auto;
        flex: 0 0 auto;
      }

      .publish-bar {
        padding: 0;
      }

      .emotion-menu {
        width: min(238px, calc(100vw - 56px));
        bottom: calc(100% + 10px);
      }

      .square-head {
        display: grid;
      }

      .filter-row {
        justify-content: flex-start;
      }

      .square-controls {
        justify-items: start;
      }

      .mode-row {
        justify-content: flex-start;
      }

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

      .result-card {
        grid-template-columns: 1fr;
      }

      .score {
        width: 100%;
        height: 48px;
      }

      .account-bubble {
        right: 14px;
        bottom: 14px;
        min-height: 40px;
        padding: 0 12px;
      }

      .auth-card {
        padding: 18px;
      }
    }
