:root {
  color-scheme: dark;
  --bg: #101112;
  --panel: #17191b;
  --panel-2: #202327;
  --text: #f2f4f0;
  --muted: #a4aaa3;
  --line: #30353a;
  --accent: #d7ff61;
  --accent-text: #11140a;
  --danger: #ff766f;
  --shadow: 0 20px 80px rgba(0, 0, 0, .28);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f7f2;
  --panel: #ffffff;
  --panel-2: #eceee8;
  --text: #161814;
  --muted: #62675f;
  --line: #d8dbd2;
  --accent: #1d6f4f;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --shadow: 0 18px 60px rgba(42, 46, 40, .12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(16px, 4vw, 44px);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  background: none;
  color: var(--text);
  font-weight: 760;
  font-size: 17px;
}

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

.page-chip {
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 7px 10px;
  border-radius: 8px;
  max-width: min(42vw, 360px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

main {
  min-height: calc(100vh - 64px);
}

.home,
.unlock,
.workspace,
.admin,
.center-message {
  min-height: calc(100vh - 64px);
  display: grid;
  place-items: center;
  padding: clamp(18px, 4vw, 44px);
}

.home-panel,
.unlock-panel {
  width: min(100%, 620px);
  display: grid;
  gap: 18px;
}

.home-panel h1,
.unlock-panel h1 {
  margin: 0;
  font-size: clamp(34px, 7vw, 76px);
  line-height: 1;
  letter-spacing: 0;
}

.open-form,
.unlock-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.open-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.unlock-panel {
  max-width: 420px;
}

input,
select {
  min-width: 0;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  padding: 13px 14px;
}

input:focus,
select:focus,
.editor:focus {
  border-color: color-mix(in srgb, var(--accent) 70%, var(--line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.open-form button,
.unlock-panel button,
.password-btn,
.save-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  color: var(--accent-text);
  background: var(--accent);
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 760;
}

.lock-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.form-error {
  margin: 0;
  color: var(--danger);
}

.workspace {
  align-items: start;
  padding-top: clamp(16px, 3vw, 34px);
}

.editor-shell {
  width: min(100%, 1120px);
  min-height: calc(100vh - 120px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: clip;
}

.editor-toolbar {
  display: grid;
  grid-template-columns: auto auto auto minmax(130px, 1fr) auto;
  align-items: end;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

.toolbar-section {
  display: flex;
  align-items: stretch;
  gap: 6px;
  min-height: 58px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 78%, transparent);
  position: relative;
}

.toolbar-label {
  position: absolute;
  top: -8px;
  left: 10px;
  padding: 0 6px;
  color: var(--muted);
  background: var(--panel-2);
  font-size: 11px;
  font-weight: 760;
  line-height: 1;
}

.format-section {
  min-width: 148px;
}

.action-section {
  border-color: transparent;
  background: transparent;
  padding: 8px 0;
}

.editor-toolbar button,
.editor-toolbar select {
  min-height: 42px;
  border-radius: 8px;
}

.tool-btn {
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  color: var(--text);
  background: transparent;
  border: 0;
  font-weight: 760;
  white-space: nowrap;
}

.editor-toolbar .password-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  white-space: nowrap;
}

.editor-toolbar select {
  width: 140px;
  min-height: 42px;
  padding: 0 10px;
  border: 0;
  background: transparent;
}

.link-panel,
.password-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto auto;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.link-panel[hidden],
.password-panel[hidden] {
  display: none;
}

.link-panel input,
.link-panel button,
.password-panel input,
.password-panel button {
  min-height: 42px;
}

.link-panel button,
.password-panel button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 760;
}

.link-panel button[type="submit"],
.password-panel button[type="submit"] {
  color: var(--accent-text);
  background: var(--accent);
}

.link-panel [data-link-cancel],
.password-panel [data-password-cancel] {
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.spacer {
  flex: 1 1 auto;
}

.status {
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.hidden-file {
  display: none;
}

.editor {
  min-height: calc(100vh - 178px);
  padding: clamp(18px, 4vw, 54px);
  outline: none;
  border: 1px solid transparent;
  font-size: 18px;
  line-height: 1.65;
}

.editor :first-child {
  margin-top: 0;
}

.editor h2,
.editor h3 {
  line-height: 1.18;
}

.editor pre {
  white-space: pre-wrap;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.editor img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 18px 0;
}

.admin {
  align-items: start;
  padding-top: clamp(16px, 3vw, 34px);
}

.admin-shell {
  width: min(100%, 1040px);
  display: grid;
  gap: 14px;
}

.admin-login {
  display: grid;
  grid-template-columns: auto 46px;
  gap: 10px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.admin-auth {
  width: min(100%, 420px);
  grid-template-columns: 1fr;
}

.admin-login button {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--accent-text);
  background: var(--accent);
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 760;
}

.admin-auth [data-admin-back] {
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.admin-login [data-admin-refresh] {
  width: 46px;
  padding: 0;
}

.admin-table-wrap {
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.admin-table th,
.admin-table td {
  text-align: left;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.admin-table th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

.admin-table a {
  color: var(--text);
  text-decoration: none;
  font-weight: 760;
}

.admin-table tr:last-child td {
  border-bottom: 0;
}

.admin-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.confirm-strip {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 14px;
  background: color-mix(in srgb, var(--danger) 10%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--danger) 34%, var(--line));
  border-radius: 8px;
}

.confirm-strip span {
  margin-right: auto;
  color: var(--text);
  font-weight: 760;
}

.confirm-strip button {
  min-height: 38px;
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-weight: 760;
}

.confirm-strip [data-delete-confirm] {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, var(--line));
}

.danger-btn,
.open-note-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  text-decoration: none;
  border-radius: 8px;
}

.open-note-btn {
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.danger-btn {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 36%, var(--line));
}

.empty-cell {
  color: var(--muted);
  text-align: center;
}

@media (max-width: 720px) {
  .topbar {
    padding: 0 12px;
  }

  .open-form {
    grid-template-columns: 1fr;
  }

  .editor-toolbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .toolbar-section,
  .action-section,
  .format-section,
  .editor-toolbar select {
    width: 100%;
  }

  .toolbar-section {
    flex-wrap: wrap;
  }

  .tool-btn,
  .password-btn,
  .save-btn {
    flex: 1 1 auto;
  }

  .link-panel,
  .password-panel {
    grid-template-columns: 1fr;
  }

  .spacer {
    display: none;
  }

  .status {
    order: 20;
    width: 100%;
  }

  .save-btn {
    flex: 1 1 130px;
  }

  .admin-login {
    grid-template-columns: 1fr;
  }

  .admin-login [data-admin-refresh] {
    width: 100%;
  }
}
