:root {
  --ink: #f4ece4;
  --muted: #b7aa9e;
  --line: #3d332c;
  --paper: #12100e;
  --sheet: #1e1916;
  --accent: #e39b8b;
  --accent-ink: #1a1210;
  --danger: #ffb4a8;
  --select: #3a2c28;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.38);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(227, 155, 139, 0.16), transparent 28rem),
    var(--paper);
}

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

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
}

.gate form {
  width: min(24rem, 100%);
  display: grid;
  gap: 0.85rem;
  padding: 1.4rem 1.2rem 1.3rem;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 1.2rem;
  box-shadow: var(--shadow);
}

.gate h1 {
  font-size: clamp(2.4rem, 8vw, 3.2rem);
}

.gate button {
  width: 100%;
}

#pin {
  letter-spacing: 0.28em;
  font-size: 1.25rem;
}

.mast-side {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  min-height: 100vh;
}

.sidebar {
  max-height: 46vh;
  overflow: auto;
  padding: 1rem 0.8rem 1.2rem;
  border-bottom: 1px solid var(--line);
  background: #181410;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.7rem;
}

.sidebar-head h2,
.current h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 500;
}

.folder-form {
  display: grid;
  gap: 0.55rem;
  margin-bottom: 0.8rem;
}

[hidden] {
  display: none !important;
}

.tree {
  display: grid;
  align-content: start;
  gap: 0.1rem;
}

.tree-row {
  display: grid;
  grid-template-columns: 1.4rem minmax(0, 1fr);
  align-items: center;
  gap: 0.1rem;
  user-select: none;
  touch-action: none;
}

body.tree-dragging,
body.tree-dragging * {
  cursor: grabbing !important;
}

.tree-ghost {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  max-width: 16rem;
  padding: 0.25rem 0.55rem;
  border: 1px solid var(--accent);
  border-radius: 0.45rem;
  background: var(--sheet);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-row.drop-before {
  box-shadow: inset 0 2px 0 var(--accent);
}

.tree-row.drop-after {
  box-shadow: inset 0 -2px 0 var(--accent);
}

.tree-row.drop-inside button.tree-item {
  background: var(--select);
}

.tree-row.dragging {
  opacity: 0.4;
}

.content {
  width: min(48rem, 100%);
  padding: 1.15rem 1rem 3rem;
}

.mast,
.current-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.8rem;
}

.mast {
  margin-bottom: 1rem;
  justify-content: flex-end;
}

.current {
  margin-bottom: 0.9rem;
}

#folder-editor:not(:empty) {
  margin-top: 0.7rem;
}

.eyebrow {
  margin: 0 0 0.2rem;
  color: var(--muted);
  font-family: "Segoe UI", sans-serif;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}

h1 {
  margin: 0;
  font-size: clamp(2.1rem, 5vw, 3.2rem);
  font-weight: 500;
  line-height: 0.9;
  letter-spacing: -0.03em;
}

.count {
  margin: 0;
  min-width: 3.2rem;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: "Segoe UI", sans-serif;
  font-size: 0.95rem;
  text-align: center;
}

.composer,
.search,
.card {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 1.1rem;
  box-shadow: var(--shadow);
}

.composer,
.folder-form {
  padding: 0.9rem;
}

.composer {
  display: grid;
  gap: 0.75rem;
}

.folder-form {
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  background: var(--sheet);
}

.import-button {
  width: 100%;
  margin: 0.2rem 0 0.85rem;
}

button:disabled {
  opacity: 0.6;
  cursor: progress;
}

label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-family: "Segoe UI", sans-serif;
  font-size: 0.82rem;
}

input,
textarea,
select {
  width: 100%;
  padding: 0.75rem 0.8rem;
  border: 1px solid #4a3e36;
  border-radius: 0.75rem;
  background: #14110f;
  color: var(--ink);
  font-size: 1rem;
}

textarea {
  resize: vertical;
  min-height: 4.2rem;
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid rgba(141, 59, 46, 0.35);
  border-color: var(--accent);
}

.composer-actions,
.current-row {
  align-items: center;
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
}

button {
  min-height: 2.75rem;
  padding: 0.55rem 1rem;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: "Segoe UI", sans-serif;
  font-size: 0.95rem;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.05);
}

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

button.danger.armed {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

button.twisty,
button.tree-item,
button.folder-open {
  background: transparent;
  color: var(--ink);
  border: 0;
  border-radius: 0.55rem;
  filter: none;
}

button.twisty {
  width: 1.4rem;
  min-height: 1.4rem;
  padding: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

button.twisty:disabled {
  visibility: hidden;
}

button.tree-item {
  cursor: grab;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  min-height: 2.05rem;
  padding: 0.2rem 0.4rem;
  text-align: left;
  font-size: 0.95rem;
}

button.tree-item:hover,
button.folder-open:hover,
button.twisty:hover {
  filter: none;
  background: var(--select);
}

button.tree-item[aria-current="true"] {
  background: var(--select);
  color: var(--accent);
}

.tree-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.78rem;
}

.folder-icon {
  width: 1rem;
  height: 1rem;
  flex: 0 0 auto;
}

.where,
.form-error,
.status,
.empty {
  margin: 0;
  font-family: "Segoe UI", sans-serif;
  font-size: 0.92rem;
}

.where,
.status,
.empty {
  color: var(--muted);
}

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

.search {
  display: grid;
  margin: 0 0 0.9rem;
  padding: 0.85rem 1rem 1rem;
}

.status {
  min-height: 1.2rem;
  margin: 0.8rem 0.15rem;
}

.list {
  display: grid;
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.card {
  display: grid;
  grid-template-columns: 0.45rem 1fr;
  overflow: hidden;
}

.ribbon {
  background: var(--accent);
}

.folder-card .ribbon {
  background: #c4a27a;
}

.card-body,
.folder-open {
  display: grid;
  gap: 0.35rem;
  padding: 0.95rem 1rem 1rem;
}

button.folder-open {
  width: 100%;
  min-height: 0;
  border-radius: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.6rem;
  text-align: left;
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-size: 1.25rem;
}

button.folder-open .when {
  flex-basis: 100%;
  padding-left: 1.6rem;
}

.card h2 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 500;
  line-height: 1.15;
}

.card h2 a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;
}

.card h2 a:hover {
  color: var(--accent);
}

.url,
.when,
.path {
  margin: 0;
  font-family: "Segoe UI", sans-serif;
}

.url,
.path {
  color: var(--accent);
  font-size: 0.92rem;
  word-break: break-word;
}

.when {
  color: var(--muted);
  font-size: 0.78rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.editor {
  display: grid;
  gap: 0.65rem;
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

@media (min-width: 860px) {
  .workspace {
    grid-template-columns: 18rem minmax(0, 1fr);
  }

  .sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    max-height: none;
    border-bottom: 0;
    border-right: 1px solid var(--line);
    padding: 1.25rem 0.85rem 2rem;
  }

  .content {
    padding: 1.7rem 1.4rem 3rem 1.5rem;
  }
}

@media (max-width: 640px) {
  .composer-actions,
  .card-top,
  .current-row,
  .folder-form .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .composer-actions button,
  .card .actions button,
  .current-row .actions button,
  .folder-form .actions button {
    width: 100%;
  }
}
