:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0c0f13;
  color: #f4f0e8;
  --cell: 10px;
  --edge: 10px;
  --blue: #54b8ff;
  --yellow: #f6c54f;
  --green: #5ee6a8;
  --pink: #ff6fae;
  --tg-top-offset: 0px;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: #0c0f13;
}

.app-shell {
  min-height: 100vh;
  padding: calc(22px + var(--tg-top-offset)) var(--edge) 36px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin: 0 auto 18px;
}

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: 18px;
}

p {
  margin: 8px 0 0;
  color: rgba(244, 240, 232, 0.76);
  font-size: 14px;
  line-height: 1.4;
}

.lead {
  max-width: 520px;
}

.telegram-link {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  flex: 0 0 auto;
  border-radius: 8px;
  padding: 0 13px;
  background: var(--blue);
  color: #061017;
  text-decoration: none;
  font-size: 14px;
  font-weight: 850;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: 0 1 680px;
}

.panel {
  margin: 14px auto 0;
  padding: 15px;
  border: 1px solid rgba(244, 240, 232, 0.12);
  border-radius: 8px;
  background: #141922;
}

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

.top-search {
  display: flex;
  flex: 1 1 380px;
  gap: 8px;
}

input {
  width: 100%;
  min-height: 38px;
  border: 1px solid rgba(244, 240, 232, 0.16);
  border-radius: 8px;
  padding: 0 12px;
  background: #0c0f13;
  color: #f4f0e8;
  font: inherit;
  font-size: 14px;
}

select {
  width: 100%;
  min-height: 38px;
  border: 1px solid rgba(244, 240, 232, 0.16);
  border-radius: 8px;
  padding: 0 12px;
  background: #0c0f13;
  color: #f4f0e8;
  font: inherit;
  font-size: 14px;
}

input:focus {
  border-color: var(--blue);
  outline: 0;
}

select:focus {
  border-color: var(--blue);
  outline: 0;
}

.result-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 8px;
  background: rgba(84, 184, 255, 0.12);
  border: 1px solid rgba(84, 184, 255, 0.22);
}

.hidden {
  display: none !important;
}

.result-content {
  display: grid;
  gap: 12px;
}

.photo-card {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.photo-card img,
.photo-card-placeholder {
  width: 112px;
  height: 112px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid rgba(244, 240, 232, 0.14);
  background: #0c0f13;
}

.photo-card-info {
  display: grid;
  gap: 0;
  color: rgba(244, 240, 232, 0.78);
  font-size: 13px;
  line-height: 1.18;
}

.photo-card-info strong {
  color: #f4f0e8;
  font-size: 15px;
}

.empty-result {
  display: grid;
  gap: 4px;
}

.empty-result span {
  color: rgba(244, 240, 232, 0.72);
  font-size: 13px;
}

.link-button {
  min-height: 0;
  width: auto;
  border-radius: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  color: #9bd7ff;
  font-size: inherit;
  font-weight: 850;
  text-decoration: underline;
  display: inline;
  line-height: inherit;
}

.show-my-floating {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 50;
  min-width: 132px;
  min-height: 42px;
  border: 1px solid rgba(244, 240, 232, 0.14);
  border-radius: 8px;
  background: #54b8ff;
  color: #061017;
  box-shadow: 0 10px 28px rgba(84, 184, 255, 0.22), 0 8px 24px rgba(0, 0, 0, 0.35);
}

.add-sheet {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  align-items: end;
  background: rgba(0, 0, 0, 0.52);
}

.add-sheet-inner {
  width: 100%;
  max-height: calc(100vh - 28px);
  overflow: auto;
  padding: 16px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(244, 240, 232, 0.14);
  border-radius: 8px 8px 0 0;
  background: #141922;
  box-shadow: 0 -16px 40px rgba(0, 0, 0, 0.42);
}

.add-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.icon-button {
  width: 38px;
  min-width: 38px;
  padding: 0;
  background: #202735;
  color: #f4f0e8;
  font-size: 20px;
}

label {
  display: grid;
  gap: 7px;
  margin-top: 12px;
  color: rgba(244, 240, 232, 0.72);
  font-size: 13px;
  font-weight: 750;
}

input[type="file"] {
  padding: 9px 10px;
}

.crop-preview {
  display: grid;
  place-items: center;
  margin-top: 12px;
  padding: 10px;
  border: 1px solid rgba(244, 240, 232, 0.14);
  border-radius: 8px;
  background: #0c0f13;
}

#crop-canvas {
  display: block;
  width: 100%;
  max-width: 360px;
  max-height: 280px;
  border: 1px solid rgba(244, 240, 232, 0.12);
  background: #05070a;
  touch-action: none;
  cursor: grab;
}

#crop-canvas:active {
  cursor: grabbing;
}

.size-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.range-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

input[type="range"] {
  min-height: 34px;
  padding: 0;
  accent-color: var(--yellow);
}

.cost-line {
  margin-top: 14px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(84, 184, 255, 0.12);
  color: #d8efff;
  font-weight: 850;
}

#pay-photo {
  width: 100%;
  margin-top: 12px;
}

.sheet-note {
  min-height: 20px;
  margin-top: 10px;
  font-size: 13px;
}

button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  padding: 0 13px;
  background: var(--yellow);
  color: #171308;
  font: inherit;
  font-size: 14px;
  font-weight: 850;
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

.board-wrap {
  width: 100%;
  margin-top: 14px;
  overflow: hidden;
  border-radius: 0;
}

.board {
  position: relative;
  width: 100%;
  min-height: 460px;
  overflow: hidden;
  border-radius: 0;
  background-color: #0a0d12;
  background-image:
    linear-gradient(rgba(255,255,255,0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.055) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
}

.tile {
  position: absolute;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 0;
  color: #061017;
  font-size: 10px;
  font-weight: 900;
  overflow: hidden;
  cursor: pointer;
}

.tile.is-match {
  outline: 2px solid #ffffff;
  outline-offset: 0;
  z-index: 3;
}

.tile.is-new {
  animation: tile-new 3s ease-out;
}

.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.35), transparent 52%);
  pointer-events: none;
}

.tile span {
  position: relative;
  z-index: 1;
}

@keyframes tile-new {
  0% {
    filter: brightness(1.35);
    outline: 2px solid var(--yellow);
    outline-offset: 0;
  }

  100% {
    filter: brightness(1);
    outline: 0 solid transparent;
    outline-offset: 0;
  }
}

.auth-ok {
  background: rgba(94, 230, 168, 0.14);
  color: #caffdf;
}

.auth-error {
  background: rgba(255, 111, 174, 0.14);
  color: #ffd4e5;
}

@media (max-width: 560px) {
  .app-shell {
    padding: calc(18px + var(--tg-top-offset)) var(--edge) 28px;
  }

  .topbar,
  .section-head {
    display: block;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr;
    margin-top: 12px;
  }

  .telegram-link {
    margin-top: 12px;
  }

  .top-search {
    display: grid;
    grid-template-columns: 1fr;
  }

  .result-panel {
    grid-template-columns: 1fr;
  }

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

  .photo-card img,
  .photo-card-placeholder {
    width: 96px;
    height: 96px;
  }

  .show-my-floating {
    right: 20px;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    min-width: 132px;
    width: auto;
    margin-top: 0;
  }

  h1 {
    font-size: 28px;
  }

  button {
    width: 100%;
    margin-top: 12px;
  }

  .link-button {
    width: auto;
    margin-top: 0;
  }

  .icon-button {
    width: 38px;
    margin-top: 0;
  }

}
