:root {
  --ink: #18201c;
  --muted: #69726f;
  --paper: #f7f4ec;
  --panel: #ffffff;
  --line: #d8d3c6;
  --brand: #166c5d;
  --brand-strong: #0d493f;
  --warm: #e6a23a;
  --ready: #2d9f72;
  --danger: #bd3a3a;
  --shadow: 0 20px 55px rgba(26, 32, 28, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

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

a {
  color: var(--brand);
  font-weight: 800;
  text-decoration: none;
}

a:hover {
  color: var(--brand-strong);
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  padding: 0 18px;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, opacity 160ms ease;
}

button:hover:not(:disabled) {
  background: var(--brand-strong);
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.eyebrow,
.panel-kicker {
  margin: 0 0 6px;
  color: var(--brand);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 4rem);
  line-height: 0.96;
}

h2 {
  margin-bottom: 8px;
  font-size: 1.12rem;
}

p {
  color: var(--muted);
  line-height: 1.5;
}

.project-switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.62);
  padding: 0 16px;
  color: var(--brand-strong);
  font-weight: 700;
  white-space: nowrap;
}

.nav-links {
  flex-wrap: wrap;
  border-radius: 8px;
}

.nav-links a {
  white-space: nowrap;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ready);
  box-shadow: 0 0 0 5px rgba(45, 159, 114, 0.14);
}

.flash {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  margin-bottom: 16px;
  padding: 12px 14px;
  font-weight: 800;
}

.flash-success {
  border-color: rgba(45, 159, 114, 0.35);
  color: var(--brand-strong);
}

.flash-error {
  border-color: rgba(189, 58, 58, 0.35);
  color: var(--danger);
}

.page-band {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
  margin-bottom: 22px;
  padding: 22px;
}

.page-band h2 {
  font-size: 1.6rem;
}

.page-band p {
  max-width: 760px;
  margin-bottom: 0;
}

.project-list {
  display: grid;
  gap: 14px;
}

.list-card {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  padding: 14px;
}

.list-card img {
  width: 150px;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  object-fit: cover;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.meta-row span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fbfaf6;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  padding: 0 18px;
}

.button-link:hover {
  background: var(--brand-strong);
  color: #fff;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.admin-actions form {
  margin: 0;
}

.danger-button {
  min-height: 42px;
  border: 1px solid rgba(189, 58, 58, 0.34);
  background: rgba(255, 255, 255, 0.9);
  color: var(--danger);
}

.danger-button:hover {
  background: rgba(189, 58, 58, 0.1);
  color: var(--danger);
}

.auth-panel,
.panel {
  width: min(520px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
  padding: 22px;
}

.two-column {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}

.two-column .panel {
  width: 100%;
}

.compact-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 12px 0;
}

.compact-row strong,
.compact-row span {
  display: block;
}

.compact-row span {
  color: var(--muted);
  font-size: 0.86rem;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.52);
  padding: 18px;
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.sidebar,
.canvas-area {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
}

.sidebar {
  display: grid;
  gap: 18px;
  padding: 18px;
}

.project-card {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}

.project-card img {
  width: 92px;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
  background: #fff;
}

.project-card p,
.block-panel p {
  margin-bottom: 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stats-grid div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf6;
  padding: 12px;
}

.stats-grid strong,
.stats-grid span {
  display: block;
}

.stats-grid strong {
  font-size: 1.35rem;
}

.stats-grid span {
  color: var(--muted);
  font-size: 0.76rem;
  overflow-wrap: anywhere;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.tab {
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}

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

.block-panel {
  min-height: 254px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.panel-link {
  margin-top: 14px;
}

.panel-link a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  padding: 0 12px;
}

.panel-link a:hover {
  background: var(--brand-strong);
  color: #fff;
}

.panel-form {
  margin-top: 12px;
}

.panel-form button {
  width: 100%;
}

.form {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
}

input[type="text"],
input[type="file"] {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 9px 11px;
  color: var(--ink);
}

.hidden {
  display: none !important;
}

.piece-preview {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.piece-preview img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
}

.ghost-button {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(189, 58, 58, 0.34);
}

.ghost-button:hover {
  background: rgba(189, 58, 58, 0.08);
  color: var(--danger);
}

.canvas-area {
  min-width: 0;
  padding: 18px;
}

.board-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.board-toolbar p {
  margin-bottom: 0;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.board-wrap {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: min(74vh, 860px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fefdf9;
  overflow: auto;
  padding: 18px;
}

.board {
  position: relative;
  width: min(100%, 820px);
  aspect-ratio: var(--template-width, var(--grid-cols, 4)) / var(--template-height, var(--grid-rows, 4));
  display: grid;
  grid-template-columns: repeat(var(--grid-cols, 4), 1fr);
  grid-template-rows: repeat(var(--grid-rows, 4), 1fr);
  background: #fff url("assets/demo-contour.png") center / cover no-repeat;
  border: 2px solid var(--ink);
  border-radius: 8px;
  overflow: hidden;
}

.board.mosaic {
  background: #fff;
}

.cell {
  display: block;
  position: relative;
  border: 1px solid rgba(24, 32, 28, 0.34);
  background: rgba(255, 255, 255, 0.16);
  padding: 0;
  border-radius: 0;
  overflow: hidden;
}

.cell form {
  margin: 0;
}

.cell:hover,
.cell.selected {
  z-index: 2;
  outline: 4px solid rgba(22, 108, 93, 0.82);
  outline-offset: -4px;
  transform: none;
}

.cell-action {
  position: absolute;
  inset: auto 8px 8px 8px;
  display: grid;
  gap: 7px;
}

.cell-tools {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 3;
  display: grid;
  gap: 6px;
}

.cell-tools form {
  display: grid;
  gap: 6px;
}

.cell-tool-button,
.cell-tools button,
.cell-action button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 32px;
  border-radius: 8px;
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 800;
  text-align: center;
}

.cell-tool-button {
  background: var(--brand);
  color: #fff;
}

.cell-tool-button:hover {
  background: var(--brand-strong);
  color: #fff;
}

.cancel-action button {
  border: 1px solid rgba(189, 58, 58, 0.34);
  background: rgba(255, 255, 255, 0.9);
  color: var(--danger);
}

.cancel-action button:hover {
  background: rgba(189, 58, 58, 0.1);
  color: var(--danger);
}

.upload-action input[type="file"] {
  min-height: 32px;
  max-width: 100%;
  border-color: rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.84);
  padding: 4px;
  font-size: 0.7rem;
}

.cell.available {
  background: rgba(255, 255, 255, 0.36);
}

.cell.reserved {
  background: rgba(230, 162, 58, 0.34);
}

.cell.uploaded {
  background: rgba(45, 159, 114, 0.26);
}

.cell.expired {
  background: rgba(189, 58, 58, 0.3);
}

.cell-number {
  position: absolute;
  top: 7px;
  left: 7px;
  display: grid;
  place-items: center;
  min-width: 27px;
  height: 24px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
}

.cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cell-author {
  position: absolute;
  inset: 0;
  display: block;
  color: #fff;
}

.cell-author > a {
  position: absolute;
  inset: auto 8px 8px 8px;
  border-radius: 6px;
  background: rgba(24, 32, 28, 0.72);
  padding: 5px 7px;
  color: #fff;
  font-size: 0.76rem;
  overflow-wrap: anywhere;
}

.cell-author > a:hover {
  color: #fff;
  background: rgba(13, 73, 63, 0.82);
}

.admin-piece-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 4;
  margin: 0;
}

.admin-piece-delete button {
  min-height: 30px;
  border: 1px solid rgba(189, 58, 58, 0.34);
  background: rgba(255, 255, 255, 0.9);
  color: var(--danger);
  padding: 0 9px;
  font-size: 0.72rem;
}

.admin-piece-delete button:hover {
  background: rgba(189, 58, 58, 0.1);
  color: var(--danger);
}

.mosaic .cell:not(.uploaded) {
  background: #f1eee5;
}

.mosaic .cell:not(.uploaded)::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: linear-gradient(135deg, rgba(24, 32, 28, 0.06) 25%, transparent 25%, transparent 50%, rgba(24, 32, 28, 0.06) 50%, rgba(24, 32, 28, 0.06) 75%, transparent 75%);
  background-size: 18px 18px;
}

@media (max-width: 960px) {
  .app-shell {
    padding: 16px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .two-column {
    grid-template-columns: 1fr;
  }

  .sidebar {
    order: 2;
  }
}

@media (max-width: 620px) {
  .topbar,
  .board-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .result-actions {
    justify-content: stretch;
  }

  .result-actions .button-link {
    flex: 1;
  }

  .project-switch {
    justify-content: center;
  }

  .project-card {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .project-card img {
    width: 72px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .list-card {
    grid-template-columns: 88px minmax(0, 1fr);
  }

  .list-card img {
    width: 88px;
  }

  .board-wrap {
    min-height: auto;
    padding: 10px;
  }

  .cell-number {
    top: 4px;
    left: 4px;
    min-width: 22px;
    height: 20px;
    font-size: 0.68rem;
  }

  .cell-action {
    inset: auto 4px 4px 4px;
  }

  .cell-tools {
    left: 4px;
    right: 4px;
    bottom: 4px;
    gap: 4px;
  }

  .cell-tools form {
    gap: 4px;
  }

  .cell-tool-button,
  .cell-tools button,
  .cell-action button {
    min-height: 26px;
    padding: 0 5px;
    font-size: 0.64rem;
  }

  .upload-action input[type="file"] {
    min-height: 28px;
    font-size: 0.6rem;
  }
}
