:root {
  color-scheme: light;
  --ink: #202124;
  --muted: #666a70;
  --line: #d9dde3;
  --paper: #ffffff;
  --surface: #f5f3ef;
  --header-bg: #f8fafc;
  --header-line: #d7dce2;
  --accent: #1f6f68;
  --accent-dark: #164f4a;
  --danger: #a63434;
  --mode-soft: #f5f3ef;
  --mode-line: #cbded9;
  --mode-panel: #fbfaf7;
  --sheet-bg: #edf4f2;
  --editor-ink: #111820;
}

body[data-context="work"] {
  --surface: #eef2f7;
  --paper: #ffffff;
  --header-bg: #f7f8f4;
  --header-line: #d8dccf;
  --accent: #315b8c;
  --accent-dark: #233f63;
  --mode-soft: #eef2f7;
  --mode-line: #bfd0e7;
  --mode-panel: #f8fafc;
  --sheet-bg: #e7eef8;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 17px;
  overflow-x: hidden;
}

button,
input,
select,
[contenteditable] {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  min-height: 40px;
  padding: 0 16px;
}

button:hover {
  background: var(--accent-dark);
}

button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

button.ghost:hover {
  background: #ece8df;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 18px 45px rgba(40, 36, 30, 0.08);
}

.login-panel h1,
.topbar h1 {
  margin: 4px 0 22px;
  font-size: clamp(2rem, 6vw, 3.8rem);
  line-height: 1;
  font-weight: 650;
  letter-spacing: 0;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0;
  text-transform: uppercase;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  margin: 16px 0;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 42px;
  padding: 8px 10px;
}

textarea {
  resize: vertical;
}

.error {
  min-height: 1.25rem;
  color: var(--danger);
}

.journal-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(220px, 1fr);
  align-items: center;
  gap: 20px;
  padding: 18px clamp(18px, 5vw, 64px);
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-line);
  box-shadow: 0 5px 18px rgba(31, 36, 43, 0.08);
  isolation: isolate;
}

.topbar h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.context-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 280px;
  padding: 4px;
  justify-self: center;
  background: #fff;
  border: 1px solid var(--header-line);
  border-radius: 999px;
  box-shadow: 0 10px 28px rgba(31, 36, 43, 0.08);
}

.context-option {
  min-height: 38px;
  padding: 0 14px;
  background: transparent;
  color: var(--accent-dark);
  border-radius: 999px;
}

.context-option:hover {
  background: rgba(255, 255, 255, 0.54);
}

.context-option.active {
  background: var(--accent);
  color: #fff;
}

.save-state {
  color: var(--muted);
  min-width: 86px;
  text-align: right;
  justify-self: end;
}

.journal-workspace {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(280px, 1fr);
  align-items: stretch;
  min-height: calc(100vh - 111px);
}

.writing-column {
  min-width: 0;
}

.control-panel {
  position: sticky;
  top: 111px;
  align-self: start;
  display: grid;
  gap: 16px;
  max-height: calc(100vh - 111px);
  overflow-y: auto;
  padding: 24px;
  background: color-mix(in srgb, var(--mode-panel) 92%, white);
  border-left: 1px solid var(--line);
}

.search-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.search-control input {
  width: 100%;
  min-width: 0;
}

.control-card {
  padding: 16px;
  background: var(--paper);
  border: 1px solid var(--mode-line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(31, 36, 43, 0.05);
}

.control-card h2 {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.editor-toolbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(48px, 1fr));
  gap: 9px;
}

.primary-actions {
  display: grid;
  gap: 10px;
}

.primary-actions button {
  width: 100%;
  min-height: 52px;
  text-align: left;
  font-size: 1rem;
  font-weight: 650;
  padding: 0 18px;
  background: var(--paper);
  border: 1px solid var(--mode-line);
  color: var(--ink);
  box-shadow: 0 5px 16px rgba(31, 36, 43, 0.05);
}

.primary-actions button:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.primary-actions .danger-action {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 32%, var(--line));
}

.primary-actions .danger-action:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.results-panel {
  padding: 22px clamp(18px, 4vw, 52px);
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.results-header {
  width: min(980px, 100%);
  margin: 0 auto 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.results-header h2 {
  margin: 0;
  font-size: 1rem;
}

.result-row {
  width: min(980px, 100%);
  margin: 0 auto 8px;
  display: grid;
  gap: 4px;
  text-align: left;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
}

.result-row:hover {
  background: #f5f3ef;
}

.tool-button {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 50px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 9px;
  font-size: 1.12rem;
}

.tool-button:hover {
  background: #ece8df;
}

.sound-control {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) 20px;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  margin: 0;
  color: var(--muted);
  user-select: none;
}

.sound-control input {
  --sound-fill: 100%;
  width: 100%;
  height: 24px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
}

.sound-control input::-webkit-slider-runnable-track {
  height: 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: linear-gradient(
    to right,
    var(--accent) 0 var(--sound-fill),
    #d8dce1 var(--sound-fill) 100%
  );
}

.sound-control input::-moz-range-track {
  height: 7px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #d8dce1;
}

.sound-control input::-moz-range-progress {
  height: 7px;
  border-radius: 999px;
  background: var(--accent);
}

.sound-control input::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  margin-top: -6.5px;
  appearance: none;
  -webkit-appearance: none;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 7px rgba(31, 36, 43, 0.24);
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.sound-control input::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 7px rgba(31, 36, 43, 0.24);
}

.sound-control input:hover::-webkit-slider-thumb,
.sound-control input:focus-visible::-webkit-slider-thumb {
  transform: scale(1.1);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent), 0 2px 7px rgba(31, 36, 43, 0.24);
}

.sound-control input:focus-visible {
  outline: none;
}

.speaker-icon {
  position: relative;
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  color: var(--muted);
}

.speaker-cone::before {
  content: "";
  position: absolute;
  left: 1px;
  top: 7px;
  width: 6px;
  height: 7px;
  border-radius: 2px 0 0 2px;
  background: currentColor;
}

.speaker-cone::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 4px;
  border-top: 6.5px solid transparent;
  border-bottom: 6.5px solid transparent;
  border-right: 8px solid currentColor;
}

.speaker-mute::before,
.speaker-mute::after {
  content: "";
  position: absolute;
  right: 0;
  top: 9px;
  width: 8px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}

.speaker-mute::before {
  transform: rotate(45deg);
}

.speaker-mute::after {
  transform: rotate(-45deg);
}

.speaker-wave {
  position: absolute;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-bottom-color: transparent;
  border-left-color: transparent;
  border-radius: 50%;
}

.speaker-wave--one {
  right: 3px;
  top: 6px;
  width: 5px;
  height: 8px;
}

.speaker-wave--two {
  right: -1px;
  top: 3px;
  width: 9px;
  height: 14px;
}

.underline-icon {
  text-decoration: underline;
}

.today-sheet {
  min-height: calc(100vh - 111px);
  padding: clamp(24px, 5vw, 72px);
  background: var(--sheet-bg);
  border-top: 5px solid var(--accent);
}

#todayEditor {
  width: min(980px, 100%);
  min-height: calc(100vh - 240px);
  display: block;
  margin: 0 auto;
  border: 0;
  outline: 0;
  color: var(--editor-ink);
  -webkit-text-fill-color: var(--editor-ink);
  background: transparent;
  caret-color: var(--accent);
  line-height: 1.65;
  font-size: 22px;
  font-weight: 450;
  overflow-wrap: anywhere;
}

#todayEditor.custom-caret-enabled {
  caret-color: transparent;
}

.typing-caret {
  position: fixed;
  z-index: 8;
  width: 3px;
  min-height: 1.35em;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent),
    0 0 7px color-mix(in srgb, var(--accent) 45%, transparent);
  pointer-events: none;
  animation: typing-caret-blink 1.35s steps(1, end) infinite;
}

@keyframes typing-caret-blink {
  0%,
  62% {
    opacity: 1;
  }

  63%,
  100% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .typing-caret {
    animation: none;
  }
}

#todayEditor:empty::before {
  content: attr(data-placeholder);
  color: #a0a4aa;
  pointer-events: none;
}

#todayEditor p,
#todayEditor div,
.note-content p,
.note-content div {
  margin: 0 0 1rem;
}

#todayEditor ul,
#todayEditor ol,
.note-content ul,
.note-content ol {
  padding-left: 1.4rem;
}

#todayEditor img,
.note-content img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 18px 0;
  border-radius: 6px;
  border: 1px solid var(--line);
}

#todayEditor details,
.note-content details {
  position: relative;
  margin: 0 0 1rem;
  padding: 10px 14px;
  border: 1px solid var(--mode-line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--paper) 58%, transparent);
}

#todayEditor summary,
.note-content summary {
  cursor: pointer;
  color: var(--accent-dark);
  font-weight: 700;
}

#todayEditor details[open] summary,
.note-content details[open] summary {
  margin-bottom: 10px;
}

.uncollapse-button {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 28px;
  min-height: 28px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--mode-line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
}

.uncollapse-button:hover {
  background: var(--mode-line);
  color: var(--ink);
}

.history {
  padding: 40px clamp(18px, 5vw, 64px) 72px;
  border-top: 1px solid var(--line);
}

.history h2 {
  width: 100%;
  margin: 0 auto 18px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
  text-transform: uppercase;
}

.note-card {
  width: min(980px, 100%);
  margin: 0 auto 18px;
  padding: 24px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.note-card time {
  display: block;
  margin-bottom: 14px;
  color: var(--muted);
  font-weight: 600;
}

.collapsed-note {
  width: min(980px, 100%);
  min-height: 44px;
  margin: 0 auto 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  text-align: left;
}

.collapsed-note:hover {
  background: var(--mode-panel);
}

.collapsed-note span:last-child {
  color: var(--muted);
  white-space: nowrap;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: -4px 0 16px;
}

.tag-chip {
  min-height: 28px;
  padding: 0 10px;
  background: var(--mode-soft);
  color: var(--accent-dark);
  border: 1px solid var(--mode-line);
  border-radius: 999px;
  font-size: 0.85rem;
}

.tag-chip:hover {
  background: var(--mode-line);
}

.note-content {
  margin: 0;
  overflow-wrap: anywhere;
  line-height: 1.55;
}

.empty-history {
  width: min(980px, 100%);
  margin: 0 auto;
  color: var(--muted);
}

dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  max-width: min(440px, calc(100vw - 32px));
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
}

.settings-dialog {
  width: min(680px, calc(100vw - 32px));
  max-width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
}

.wide-dialog {
  width: min(920px, calc(100vw - 32px));
  max-width: min(920px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
}

dialog::backdrop {
  background: rgba(20, 20, 20, 0.35);
  backdrop-filter: blur(3px);
}

.dialog-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 24px;
  background: color-mix(in srgb, var(--mode-panel) 94%, white);
  border-bottom: 1px solid var(--line);
}

.dialog-header h2,
.dialog-header p {
  margin: 0;
}

.dialog-header h2 {
  margin-top: 3px;
  font-size: 1.55rem;
}

.dialog-close {
  width: 42px;
  min-height: 42px;
  padding: 0;
  font-size: 1.65rem;
  line-height: 1;
}

.dialog-form {
  padding: 24px;
}

.dialog-form h2 {
  margin: 0 0 12px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.dialog-section {
  border-top: 1px solid var(--line);
  padding: 22px 24px 24px;
}

.dialog-section h2 {
  margin: 0 0 12px;
}

.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.backup-dialog-body {
  display: grid;
  gap: 10px;
  border-top: 0;
}

.backup-dialog-body button {
  width: 100%;
  min-height: 48px;
}

.pin-change-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.import-controls,
.import-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

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

.import-section textarea {
  width: 100%;
  font-family: inherit;
  line-height: 1.45;
}

.import-review {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.import-row {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.import-row.possible-duplicate {
  margin-top: 10px;
  padding: 14px;
  border: 1px solid #d6a12e;
  border-radius: 9px;
  background: #fff9e8;
}

.import-row.possible-duplicate .import-warning {
  color: #76520a;
  font-weight: 650;
}

.import-row textarea {
  margin-top: 10px;
}

.import-warning {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.dialog-note {
  min-height: 1.3rem;
  color: var(--muted);
}

.pin-form {
  width: min(380px, calc(100vw - 32px));
  padding: 28px;
}

.pin-form h2 {
  font-size: 1.6rem;
  line-height: 1.1;
}

.pin-form label {
  margin-bottom: 18px;
}

.pin-form .dialog-actions {
  margin-top: 4px;
}

#personalPin {
  width: 100%;
  min-width: 0;
  font-size: 1.6rem;
  letter-spacing: 0.18em;
  text-align: center;
  -webkit-text-security: disc;
}

@media (max-width: 680px) {
  .topbar {
    align-items: flex-start;
    grid-template-columns: 1fr;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .context-switch {
    width: min(100%, 280px);
    justify-self: start;
  }

  .save-state {
    text-align: left;
  }

  .journal-workspace {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
    grid-row: 1;
    max-height: none;
    padding: 18px;
    border-left: 0;
    border-bottom: 1px solid var(--line);
  }

  .writing-column {
    grid-row: 2;
  }

  .editor-toolbar {
    grid-template-columns: repeat(4, 1fr);
  }

  .pin-change-grid,
  .import-controls,
  .import-meta {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
}
