:root {
  --paper: #f4e6c8;
  --ink: #4a301c;
  --muted: #7a5b40;
  --line: rgba(74, 48, 28, 0.28);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  background: #1c140e;
  color: var(--ink);
  font-family: Literata, Palatino, serif;
}

button, input { font: inherit; color: inherit; }
button { touch-action: manipulation; }
:focus-visible { outline: 2px solid #8d5a32; outline-offset: 2px; }

.shell {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  min-height: 100dvh;
}

aside {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 18px 14px 12px;
  background:
    radial-gradient(circle at 12% 0%, rgba(255, 252, 245, 0.7), transparent 42%),
    linear-gradient(180deg, #f8efdc, #f1e0c2);
  border-right: 1px solid rgba(92, 58, 30, 0.18);
}

.kicker {
  margin: 0;
  font-family: "Marck Script", cursive;
  font-size: 22px;
  color: #8d3b2c;
}

aside h1 {
  margin: 0 0 6px;
  font-family: Oranienbaum, "Times New Roman", serif;
  font-size: 34px;
  font-weight: 400;
  line-height: 0.95;
}

.lead {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.4;
}

.offline {
  max-width: 640px;
  margin: 12vh auto;
  padding: 0 24px;
  color: #f6edd8;
}

.offline h1 {
  margin: 0 0 12px;
  font-family: Oranienbaum, "Times New Roman", serif;
  font-size: 40px;
  font-weight: 400;
}

.offline p { font-size: 18px; line-height: 1.45; }

#search, .word input[type="text"], #lock-pass {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 252, 246, 0.85);
  border-radius: 10px;
  padding: 9px 11px;
  outline: none;
  margin-bottom: 8px;
  font-size: 16px;
}

#search:focus { border-color: #8d5a32; box-shadow: 0 0 0 3px rgba(141, 90, 50, 0.15); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }

.chips button, .text-btn, .crop-actions button, #lock-form button {
  border: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.7);
  border-radius: 999px;
  min-height: 40px;
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
}

.chips button.is-on, .primary, .crop-actions .primary {
  background: #5c3a1e;
  color: #f6edd8;
  border-color: #5c3a1e;
}

.list-meta {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

#places { overflow: auto; flex: 1; min-height: 0; margin: 0 -6px; padding: 0 6px 8px; }

.place {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 8px;
  text-align: left;
  border: 0;
  border-radius: 10px;
  padding: 7px 8px;
  background: transparent;
  cursor: pointer;
}

.place:hover, .place.is-on { background: rgba(92, 58, 30, 0.08); }

.place strong { font-weight: 650; font-size: 15px; }

.place em { color: var(--muted); font-size: 12px; }

.place small {
  grid-column: 1 / -1;
  color: #6d4c34;
  font-size: 12px;
}

main {
  min-width: 0;
  overflow: auto;
  padding: 28px 32px 48px;
}

.banner {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #f3d7c4;
  color: #6e2430;
}

#status {
  min-height: 1.3em;
  margin: 0 0 12px;
  color: #f6edd8;
  font-size: 14px;
}

.empty-editor {
  margin: 12vh 0 0;
  color: #f6edd8;
  font-family: Oranienbaum, serif;
  font-size: 28px;
}

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

.editor-head h2 {
  margin: 0;
  color: #f8efdc;
  font-family: Oranienbaum, serif;
  font-size: 40px;
  font-weight: 400;
  line-height: 1;
}

.editor-head p { margin: 6px 0 0; color: #d9c4a4; font-size: 14px; }

.editor-actions, .word-actions, .crop-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.word {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 14px;
  margin-bottom: 12px;
  padding: 12px;
  border-radius: 14px;
  background:
    linear-gradient(180deg, #f8f0de, #f3e4c6);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
}

.preview {
  width: 112px;
  height: 112px;
  border-radius: 8px;
  overflow: hidden;
  background: #efe2c8;
  border: 1px solid rgba(92, 58, 30, 0.25);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  padding: 6px;
}

.preview img { width: 100%; height: 100%; object-fit: cover; display: block; }

.word label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }

.back-list { display: none; margin-bottom: 8px; }

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

.add-row { margin: 8px 0 18px; }

#crop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  background: rgba(16, 10, 6, 0.78);
}

#crop[hidden] { display: none; }

.crop-dialog, .lock-card {
  width: min(620px, 100%);
  max-height: calc(100dvh - 24px);
  overflow: auto;
  padding: 18px;
  border-radius: 16px;
  background: linear-gradient(180deg, #f8f0de, #f3e4c6);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
}

#lock {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  background: rgba(16, 10, 6, 0.78);
}

#lock[hidden] { display: none; }

.lock-card { width: min(420px, 100%); }

.lock-card h2 {
  margin: 0;
  font-family: Oranienbaum, serif;
  font-size: 32px;
  font-weight: 400;
}

.lock-card p { color: var(--muted); }

.crop-dialog h2 {
  margin: 0;
  font-family: Oranienbaum, serif;
  font-size: 32px;
  font-weight: 400;
}

.crop-lead { margin: 4px 0 12px; color: var(--muted); font-size: 14px; }

.crop-stage {
  width: min(92vw, 52dvh, 520px);
  aspect-ratio: 1;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(45deg, #cfc3ae 25%, transparent 25%),
    linear-gradient(-45deg, #cfc3ae 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #cfc3ae 75%),
    linear-gradient(-45deg, transparent 75%, #cfc3ae 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-color: #e7dcc6;
  border-radius: 10px;
  touch-action: none;
  cursor: grab;
}

.crop-stage img {
  position: absolute;
  top: 0;
  left: 0;
  max-width: none;
  user-select: none;
  pointer-events: none;
}

.zoom { display: flex; align-items: center; gap: 10px; margin: 12px 0 4px; font-size: 14px; }

.zoom input { flex: 1; }

.crop-error { min-height: 1.2em; margin: 0 0 8px; color: #8d3b2c; font-size: 13px; }

.crop-actions { justify-content: flex-end; }

@media (min-width: 1200px) {
  .shell { grid-template-columns: 360px minmax(0, 1fr); }
  main { padding: 36px 48px 64px; }
}

@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .shell:not(.is-editing) main { display: none; }
  .shell.is-editing aside { display: none; }
  .back-list { display: inline-flex; }
  aside, main {
    min-height: 100dvh;
    padding: max(16px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }
  .editor-head { flex-direction: column; align-items: stretch; }
  .editor-head h2 { font-size: 32px; }
  .editor-actions, .word-actions, .crop-actions { align-items: stretch; }
  .editor-actions button, .word-actions button, .crop-actions button { flex: 1 1 auto; }
}

@media (max-width: 560px) {
  .word { grid-template-columns: 1fr; }
  .preview { width: min(100%, 220px); height: auto; aspect-ratio: 1; }
  aside h1 { font-size: 28px; }
}

@media (max-height: 520px) and (min-width: 801px) {
  .lead, .kicker { display: none; }
  aside h1 { font-size: 26px; }
  aside { padding-top: 10px; }
  main { padding: 12px 16px 20px; }
  .editor-head h2 { font-size: 28px; }
}

@media (pointer: coarse) {
  .place { padding: 10px 8px; }
}
