:root {
  --bg-top: #f8f1e4;
  --bg-bottom: #eee5d8;
  --panel: #fffaf2;
  --ink: #2e2923;
  --muted: #6f675c;
  --line: #e2d5c3;
  --accent: #816036;
  --accent-soft: #f0e1cb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Georgia, 'Times New Roman', serif;
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

.shell {
  width: min(1240px, 94vw);
  margin: 1rem auto 3.5rem;
  display: grid;
  gap: 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 8px;
  z-index: 8;
  backdrop-filter: blur(4px);
}

.topbar h1 {
  margin: 0;
}

.topbar-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tabs button {
  min-height: 42px;
}

.gallery-head h2 {
  margin: 0;
}

.gallery-head .muted {
  margin-top: 0.35rem;
}

.muted,
.status {
  color: var(--muted);
  margin: 0;
}

.hidden {
  display: none !important;
}

.row,
.stack {
  display: grid;
  gap: 0.7rem;
}

.row {
  grid-template-columns: 1fr auto;
}

.upload-panel {
  display: grid;
  gap: 1rem;
}

.upload-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.95rem;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.62rem 0.72rem;
  background: #fff;
}

textarea {
  resize: vertical;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 0.62rem 0.9rem;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
}

button.secondary {
  background: var(--accent-soft);
  color: #4f3c23;
}

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

.result-list {
  margin: 0;
  padding-left: 1.15rem;
  max-height: 180px;
  overflow: auto;
}

.crop-wrap {
  min-height: 160px;
  max-height: 340px;
  overflow: hidden;
  border-radius: 12px;
  border: 1px dashed var(--line);
  background: #f9f4ec;
}

.crop-wrap img {
  display: block;
  max-width: 100%;
}

.gallery-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(12, 1fr);
  grid-auto-rows: 72px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
}

.testimony-list {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.8rem;
}

.testimony-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 0.85rem;
  display: grid;
  gap: 0.5rem;
}

.testimony-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
}

.testimony-body p {
  margin: 0 0 0.6rem;
}

.testimony-body p:last-child {
  margin-bottom: 0;
}

.frame {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #eadfcd;
  transition: transform 0.2s ease;
}

.frame:hover {
  transform: translateY(-2px);
}

.frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
}

.pattern-a { grid-column: span 4; grid-row: span 4; }
.pattern-b { grid-column: span 3; grid-row: span 3; }
.pattern-c { grid-column: span 5; grid-row: span 4; }
.pattern-d { grid-column: span 3; grid-row: span 2; }
.pattern-e { grid-column: span 4; grid-row: span 3; }
.pattern-f { grid-column: span 6; grid-row: span 4; }
.pattern-g { grid-column: span 2; grid-row: span 2; }
.pattern-h { grid-column: span 6; grid-row: span 5; }

.badge {
  position: absolute;
  top: 8px;
  left: 8px;
  border-radius: 999px;
  padding: 0.2rem 0.56rem;
  font-size: 0.76rem;
  color: #4b361a;
  background: rgba(255, 251, 245, 0.92);
}

.meta {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.55rem;
  display: grid;
  gap: 0.35rem;
  color: #fff;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0));
}

.frame-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.5rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.62), rgba(0, 0, 0, 0));
}

.meta-title {
  margin: 0;
  font-size: 0.95rem;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.vote {
  font-size: 0.9rem;
  line-height: 1;
  min-height: 38px;
  padding: 0.5rem 0.65rem;
  border-radius: 999px;
  background: #fff;
  color: #46331a;
}

.open-photo {
  border: 0;
  border-radius: 999px;
  min-height: 38px;
  padding: 0.5rem 0.65rem;
  background: rgba(255, 255, 255, 0.88);
  color: #44311a;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.lightbox.hidden {
  display: none;
}

.lightbox img {
  max-width: min(94vw, 1200px);
  max-height: 78vh;
  border-radius: 10px;
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: #fff;
  color: #2b241b;
}

.lightbox-caption {
  color: #fff;
  margin-top: 0.65rem;
  text-align: center;
}

@media (max-width: 980px) {
  .upload-grid {
    grid-template-columns: 1fr;
  }

  .gallery-grid {
    grid-template-columns: repeat(6, 1fr);
    grid-auto-rows: 70px;
  }

  .pattern-a, .pattern-c, .pattern-f, .pattern-h { grid-column: span 6; }
  .pattern-b, .pattern-d, .pattern-e { grid-column: span 3; }
  .pattern-g { grid-column: span 2; }
}

@media (max-width: 640px) {
  .topbar {
    position: static;
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar-actions button {
    width: 100%;
  }

  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: 172px;
  }

  .pattern-a, .pattern-b, .pattern-c, .pattern-d, .pattern-e, .pattern-f, .pattern-g, .pattern-h {
    grid-column: span 2;
    grid-row: span 1;
  }

  .frame-controls {
    justify-content: space-between;
  }
}
