:root {
  --bg: #11100f;
  --bg-2: #1a1816;
  --panel: rgba(255, 255, 255, 0.075);
  --panel-strong: rgba(255, 255, 255, 0.12);
  --text: #f8f3ed;
  --muted: #b8afa4;
  --line: rgba(255, 255, 255, 0.12);
  --accent: #f2b15d;
  --accent-2: #d98638;
  --danger: #ff6b6b;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.45);
  --radius: 24px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% -10%, rgba(242, 177, 93, 0.22), transparent 34rem),
    radial-gradient(circle at 90% 10%, rgba(255, 255, 255, 0.08), transparent 22rem),
    linear-gradient(160deg, #11100f 0%, #191512 50%, #0c0c0c 100%);
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

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

.app-shell {
  width: min(760px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px calc(94px + var(--safe-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 2px 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 9vw, 3.6rem);
  line-height: 0.95;
  letter-spacing: -0.08em;
}

h2 {
  margin-bottom: 0;
  font-size: 1.08rem;
  letter-spacing: -0.03em;
}

.icon-button,
.fab {
  width: 54px;
  height: 54px;
  border: 0;
  border-radius: 19px;
  display: grid;
  place-items: center;
  color: #1a1208;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 14px 30px rgba(242, 177, 93, 0.24);
  font-size: 2.1rem;
  font-weight: 700;
  line-height: 1;
}

.icon-button:active,
.fab:active,
.primary-button:active,
.secondary-button:active,
.ghost-button:active,
.danger-button:active {
  transform: scale(0.98);
}

.tools {
  margin-bottom: 14px;
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px);
}

.search-wrap span {
  color: var(--accent);
  font-size: 1.25rem;
  font-weight: 800;
}

.search-wrap input {
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-size: 1rem;
}

.search-wrap input::placeholder,
textarea::placeholder,
input::placeholder {
  color: rgba(248, 243, 237, 0.45);
}

.panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.105), rgba(255, 255, 255, 0.055));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
}

.counter {
  min-width: 34px;
  padding: 5px 10px;
  border-radius: 999px;
  color: #211508;
  background: var(--accent);
  font-size: 0.8rem;
  font-weight: 900;
  text-align: center;
}

.table-wrap {
  position: relative;
  min-height: 260px;
}

.notes-table {
  width: 100%;
  border-collapse: collapse;
}

.notes-table thead {
  display: none;
}

.notes-table tr {
  border-bottom: 1px solid var(--line);
}

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

.note-row {
  position: relative;
}

.note-row button {
  width: 100%;
  min-height: 62px;
  padding: 0 52px 0 18px;
  border: 0;
  color: var(--text);
  background: transparent;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.note-row button::after {
  content: "›";
  position: absolute;
  right: 20px;
  color: var(--accent);
  font-size: 1.7rem;
  opacity: 0.9;
}

.note-row button:hover {
  background: rgba(255, 255, 255, 0.06);
}

.note-title {
  overflow: hidden;
  font-size: 1rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty {
  display: none;
  min-height: 260px;
  padding: 42px 24px;
  text-align: center;
  place-items: center;
  align-content: center;
}

.empty.visible {
  display: grid;
}

.empty-icon {
  width: 58px;
  height: 58px;
  margin-bottom: 16px;
  border: 1px dashed rgba(242, 177, 93, 0.75);
  border-radius: 21px;
  display: grid;
  place-items: center;
  color: var(--accent);
  font-size: 2rem;
}

.empty h3 {
  margin-bottom: 6px;
  font-size: 1.08rem;
}

.empty p {
  max-width: 310px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.fab {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: calc(18px + var(--safe-bottom));
  z-index: 20;
}

@media (min-width: 680px) {
  .fab {
    display: none;
  }
}

@media (max-width: 679px) {
  .topbar .icon-button {
    display: none;
  }
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(10px);
}

.overlay.open {
  display: grid;
}

.modal {
  width: min(680px, 100%);
  max-height: calc(100vh - 28px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  margin: auto;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: linear-gradient(180deg, #22201d, #141312);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sheet {
  display: flex;
  flex-direction: column;
}

.reader {
  display: flex;
  flex-direction: column;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.modal-head.sticky {
  position: sticky;
  top: 0;
  z-index: 2;
  background: rgba(34, 32, 29, 0.96);
  backdrop-filter: blur(12px);
}

.reader-title-block {
  min-width: 0;
}

#viewTitle {
  overflow-wrap: anywhere;
}

.ghost-button,
.secondary-button,
.primary-button,
.danger-button {
  border: 0;
  border-radius: 15px;
  padding: 12px 15px;
  font-weight: 850;
}

.ghost-button,
.secondary-button {
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
}

.primary-button {
  color: #1a1208;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.danger-button {
  color: #241010;
  background: var(--danger);
}

.form {
  overflow-y: auto;
  padding: 18px;
}

.form label {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.form input,
.form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  outline: 0;
  color: var(--text);
  background: rgba(255, 255, 255, 0.075);
}

.form input {
  min-height: 54px;
  padding: 0 15px;
}

.form textarea {
  min-height: 240px;
  padding: 15px;
  line-height: 1.55;
  resize: vertical;
}

.form input:focus,
.form textarea:focus,
.search-wrap:focus-within {
  border-color: rgba(242, 177, 93, 0.8);
  box-shadow: 0 0 0 4px rgba(242, 177, 93, 0.1);
}

.form-actions,
.reader-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.reader-body {
  overflow-y: auto;
  padding: 20px 18px 8px;
  color: #f3eee8;
  line-height: 1.66;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.reader-actions {
  padding: 14px 18px 18px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + var(--safe-bottom));
  z-index: 80;
  max-width: min(420px, calc(100% - 32px));
  padding: 12px 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: rgba(28, 25, 22, 0.92);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

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

@media (max-width: 420px) {
  .modal {
    border-radius: 24px;
  }

  .modal-head,
  .form,
  .reader-body,
  .reader-actions {
    padding-left: 14px;
    padding-right: 14px;
  }

  .ghost-button,
  .secondary-button,
  .primary-button,
  .danger-button {
    padding: 11px 12px;
  }
}
