/* styles.css */
:root {
  --ink: #111;
  --paper: #fafafa;
  --card: #fff;
  --green: #1b9a61;
  --line: #e7e7e7;
  --items-per-row: 4;
}

html {
  scrollbar-gutter: stable;
}

* {
  box-sizing: border-box;
}

body {
  position: relative;
  min-height: 100vh;
  margin: 0;
  padding-bottom: 12px;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    repeating-linear-gradient(
      45deg,
      transparent 0 23px,
      rgba(58, 73, 86, .035) 23px 24px,
      transparent 24px 47px
    ),
    repeating-linear-gradient(
      -45deg,
      transparent 0 23px,
      rgba(58, 73, 86, .028) 23px 24px,
      transparent 24px 47px
    );
  background-attachment: fixed;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body::before {
  position: fixed;
  z-index: 0;
  inset: 0;
  pointer-events: none;
  content: "";
  background:
    radial-gradient(circle 8px at 36px 27px, #ad5f62 0 96%, transparent),
    radial-gradient(circle 8px at 44px 41px, #557996 0 96%, transparent),
    radial-gradient(circle 8px at 28px 41px, #aa8e55 0 96%, transparent),
    conic-gradient(
      from -30deg at 36px 36px,
      #ad5f62 0 33.333%,
      #557996 0 66.666%,
      #aa8e55 0 100%
    );
  background-position: 10px 7px;
  background-size: 132px 132px;
  mask-image: radial-gradient(circle at 36px 36px, #000 0 14px, transparent 15px);
  mask-position: 10px 7px;
  mask-size: 132px 132px;
  opacity: .115;
}

body > * {
  position: relative;
  z-index: 1;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1260px;
  margin: auto;
  padding: 14px 12px 6px;
}

.header-controls {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  flex: 0 0 auto;
}

.header-password,
.header-group {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #555;
  font-size: .72rem;
  font-weight: 650;
}

.header-password input,
.header-group input {
  width: 96px;
  padding: 4px 6px;
  border: 1px solid #b9b9b9;
  border-radius: 5px;
  font: inherit;
}

.header-group input {
  width: 86px;
}

.header-password-status {
  position: absolute;
  top: calc(100% + 1px);
  right: 0;
  color: #b42318;
  font-size: .67rem;
  font-weight: 700;
  white-space: nowrap;
}

.header-density {
  display: grid;
  width: 94px;
  flex: 0 0 94px;
  gap: 3px;
  contain: layout;
}

.grid-ticks {
  display: flex;
  justify-content: space-between;
  padding: 0 1px;
  color: #888;
  font-size: .57rem;
  line-height: .8;
  transform: translateY(-2px);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

h1 {
  flex: 0 0 auto;
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: -.02em;
}

main {
  max-width: 1260px;
  margin: auto;
  padding: 4px 12px 8px;
}

.categories {
  display: flex;
  gap: 7px;
  margin: 0 0 8px;
  overflow-x: auto;
  padding: 1px 0 3px;
  scrollbar-width: none;
  white-space: nowrap;
}

.category {
  flex: 0 0 auto;
  padding: 7px 11px;
  border: 1px solid #111;
  border-radius: 2px;
  color: #fff;
  background: linear-gradient(145deg, #252525 0%, #0e0e0e 58%, #1b1b1b 100%);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .14);
  clip-path: polygon(5px 0, 100% 0, calc(100% - 5px) 100%, 0 100%);
  cursor: pointer;
  font: inherit;
  font-size: .78rem;
  transition: opacity .15s;
}

.category.disabled {
  opacity: .4;
}

.photo-tool {
  margin: 12px 0 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.group-share {
  margin: 7px 0 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.group-share summary {
  padding: 7px 10px;
  cursor: pointer;
  font-size: .82rem;
  font-weight: 700;
}

.group-share-body {
  display: grid;
  justify-items: start;
  gap: 7px;
  padding: 8px 10px 10px;
  border-top: 1px solid var(--line);
}

.group-share-body p {
  margin: 0;
  color: #555;
  font-size: .78rem;
}

#group-share-link {
  max-width: 100%;
  overflow-wrap: anywhere;
  color: #333;
  font-size: .72rem;
}

#group-share-qr {
  width: min(228px, 100%);
  height: auto;
  border: 1px solid var(--line);
  image-rendering: pixelated;
}

#copy-group-link {
  padding: 6px 10px;
  border: 1px solid #aaa;
  border-radius: 2px;
  background: #fff;
  cursor: pointer;
  clip-path: polygon(4px 0, 100% 0, calc(100% - 4px) 100%, 0 100%);
}

.photo-tool summary {
  padding: 8px 10px;
  cursor: pointer;
  font-size: .86rem;
  font-weight: 700;
}

.photo-tool-body {
  padding: 0 10px 10px;
  border-top: 1px solid var(--line);
}

.photo-tool-intro {
  max-width: 760px;
  margin: 8px 0;
  color: #555;
  font-size: .84rem;
  line-height: 1.45;
}

.photo-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.photo-controls label,
.memory-note {
  display: grid;
  gap: 5px;
  color: #555;
  font-size: .75rem;
  font-weight: 650;
}

.photo-controls input,
.memory-note textarea {
  width: 100%;
  min-width: 0;
  padding: 7px;
  border: 1px solid #b9b9b9;
  border-radius: 5px;
  color: var(--ink);
  background: #fff;
  font: inherit;
  font-size: .82rem;
}

.photo-picker.locked {
  color: #8a8a8a;
  cursor: not-allowed;
  opacity: .65;
}

.photo-picker.locked input {
  cursor: not-allowed;
}

#analysis-code.password-error,
#group-name.group-error {
  border-color: #b42318;
  box-shadow: 0 0 0 2px rgba(180, 35, 24, .14);
}

.photo-preview,
.memory-photo {
  display: block;
  width: min(280px, 100%);
  max-height: 280px;
  margin: 8px 0;
  border-radius: 7px;
  object-fit: contain;
  background: #f1f1f1;
}

.photo-actions,
.result-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.photo-actions button,
.result-actions button {
  padding: 7px 11px;
  border: 1px solid #aaa;
  border-radius: 2px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
  font: inherit;
  font-size: .78rem;
  clip-path: polygon(4px 0, 100% 0, calc(100% - 4px) 100%, 0 100%);
}

.photo-actions .primary-action,
.result-actions .primary-action {
  color: #fff;
  border-color: #111;
  background: linear-gradient(145deg, #252525 0%, #0e0e0e 58%, #1b1b1b 100%);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .14);
}

.photo-actions button:disabled,
.result-actions button:disabled {
  cursor: wait;
  opacity: .5;
}

.keep-photo,
.share-all {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
}

.photo-status {
  min-height: 18px;
  margin: 7px 0 0;
  color: #555;
  font-size: .8rem;
}

.analysis-result,
.saved-memories {
  margin-top: 10px;
}

.analysis-result {
  max-width: 800px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fafafa;
}

.food-candidate.with-media {
  display: grid;
  grid-template-columns: minmax(90px, 132px) minmax(0, 1fr);
  gap: 9px;
  padding-left: 0;
  border-left: 0;
}

.candidate-media-strip {
  display: flex;
  gap: 5px;
  min-width: 0;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
}

.candidate-media {
  flex: 0 0 108px;
  width: 108px;
  height: 108px;
  padding: 0;
  overflow: hidden;
  scroll-snap-align: start;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f4f4f4;
  cursor: pointer;
}

.candidate-media img,
.candidate-media .food-art {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background-position: center;
  background-size: contain;
}

.candidate-reference .food-art {
  background-repeat: no-repeat;
}

.candidate-body {
  min-width: 0;
}

.candidate-selection {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 5px;
  color: #555;
  font-size: .72rem;
  font-weight: 650;
}

.analysis-summary {
  margin: 0 0 13px;
  font-size: .92rem;
  line-height: 1.45;
}

.analysis-section {
  margin-top: 13px;
}

.analysis-section h3,
.saved-memories h2 {
  margin: 0 0 7px;
  font-size: .86rem;
}

.food-candidate {
  margin: 7px 0;
  padding-left: 10px;
  border-left: 2px solid #ccc;
}

.food-candidate h4,
.food-candidate p,
.analysis-section p {
  margin: 3px 0;
  font-size: .8rem;
  line-height: 1.4;
}

.candidate-korean {
  font-weight: 500;
}

.confidence,
.memory-date,
.empty-result {
  color: #707070;
}

.eating-list {
  margin: 5px 0 0;
  padding-left: 20px;
  font-size: .8rem;
  line-height: 1.45;
}

.memory-note {
  margin-top: 13px;
}

.saved-memories h2 {
  padding-top: 3px;
}

#memories {
  display: grid;
  gap: 10px;
}

.memory-card {
  max-width: 800px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.memory-date {
  display: block;
  margin-bottom: 7px;
  font-size: .7rem;
}

.memory-contributor {
  margin: -3px 0 6px;
  font-size: .76rem;
  font-weight: 700;
}

.memory-group {
  margin: -3px 0 6px;
  color: #777;
  font-size: .68rem;
}

.saved-note {
  margin: 12px 0 0;
  padding: 8px;
  border-radius: 5px;
  background: #f4f4f4;
  font-size: .8rem;
  line-height: 1.4;
}

.grid {
  display: grid;
  grid-template-columns: repeat(var(--items-per-row), minmax(0, 1fr));
  gap: 6px;
}

html[data-grid-columns="1"] .grid {
  grid-template-columns: minmax(0, 560px);
  justify-content: center;
}

.card {
  position: relative;
  min-width: 0;
  padding: 2px 3px 4px;
  overflow: hidden;
  background: var(--card);
  border: 2px solid transparent;
  border-radius: 6px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .06);
  transition: border-color .18s, transform .18s;
}

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

.card.checked {
  border-color: var(--green);
}

.category-disabled .food-art {
  filter: grayscale(1);
  opacity: .35;
}

.category-disabled .labels {
  color: #8d8d8d;
  opacity: .7;
}

.food-button {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
}

.food-art {
  display: block;
  width: 148px;
  height: 148px;
  margin: 0 auto;
  background-repeat: no-repeat;
  background-size: 300% 200%;
}

html[data-grid-columns="1"] .grid .food-art {
  width: min(512px, calc(100vw - 48px));
  height: auto;
  aspect-ratio: 1;
  background-image: var(--individual-art);
  background-position: center;
  background-size: contain;
}

.sheet-1 {
  background-image: url("/assets/food-normalised-sprite-1.webp?v=20260731b");
}

.sheet-2 {
  background-image: url("/assets/food-normalised-sprite-2.webp?v=20260731b");
}

.sheet-3 {
  background-image: url("/assets/food-normalised-sprite-3.webp?v=20260731b");
}

.sheet-4 {
  background-image: url("/assets/food-normalised-sprite-4.webp?v=20260731b");
}

.position-0 {
  background-position: 0 0;
}

.position-1 {
  background-position: 50% 0;
}

.position-2 {
  background-position: 100% 0;
}

.position-3 {
  background-position: 0 100%;
}

.position-4 {
  background-position: 50% 100%;
}

.position-5 {
  background-position: 100% 100%;
}

.labels {
  min-height: 31px;
  padding-right: 18px;
  overflow-x: auto;
  scrollbar-width: none;
  text-align: center;
  white-space: nowrap;
}

.categories::-webkit-scrollbar,
.candidate-media-strip::-webkit-scrollbar,
.labels::-webkit-scrollbar {
  height: 0;
}

.categories.is-scrolling,
.candidate-media-strip.is-scrolling,
.labels.is-scrolling {
  scrollbar-width: thin;
}

.categories.is-scrolling::-webkit-scrollbar,
.candidate-media-strip.is-scrolling::-webkit-scrollbar,
.labels.is-scrolling::-webkit-scrollbar {
  height: 3px;
}

.translated,
.korean {
  display: block;
  width: max-content;
  min-width: 100%;
}

.translated {
  font-size: clamp(.66rem, 1.7vw, .88rem);
  line-height: 1.25;
}

.korean {
  margin-top: 2px;
  font-size: clamp(.62rem, 1.5vw, .76rem);
  line-height: 1.2;
}

.tick {
  position: absolute;
  right: 3px;
  bottom: 4px;
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  padding: 0;
  border: 1px solid #c6c6c6;
  border-radius: 50%;
  color: transparent;
  background: #fff;
  cursor: pointer;
  font-size: .58rem;
  font-weight: 900;
}

.checked .tick {
  color: #fff;
  border-color: var(--green);
  background: var(--green);
}

.tick:disabled {
  cursor: wait;
  opacity: .5;
}

select {
  min-width: 86px;
  padding: 4px 23px 4px 6px;
  border: 1px solid #b9b9b9;
  border-radius: 4px;
  color: var(--ink);
  background: #fff;
  font: inherit;
  font-size: .78rem;
}

#grid-slider {
  width: 94px;
  height: 2px;
  margin: 0;
  border-radius: 1px;
  background: #bbb;
  cursor: pointer;
  outline: none;
  appearance: none;
  user-select: none;
}

.header-density,
.grid-ticks,
.grid-ticks span {
  user-select: none;
  -webkit-user-select: none;
}

#grid-slider::-webkit-slider-thumb {
  width: 9px;
  height: 9px;
  border: 0;
  border-radius: 50%;
  background: #222;
  cursor: pointer;
  appearance: none;
}

#grid-slider::-moz-range-thumb {
  width: 9px;
  height: 9px;
  border: 0;
  border-radius: 50%;
  background: #222;
  cursor: pointer;
}

dialog {
  width: min(430px, calc(100vw - 28px));
  padding: 20px 24px 25px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 18px 70px rgba(0, 0, 0, .28);
  text-align: center;
}

.detail-gallery {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.detail-gallery h3 {
  margin: 0 0 7px;
  font-size: .84rem;
}

#detail-gallery-image {
  display: block;
  width: 100%;
  max-height: 300px;
  border-radius: 7px;
  object-fit: contain;
  background: #f2f2f2;
}

.gallery-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 6px;
}

.gallery-controls button {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid #aaa;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  font-size: 1.2rem;
}

#detail-gallery-position,
#detail-gallery-date,
#detail-gallery-note {
  margin: 4px 0;
  color: #666;
  font-size: .75rem;
}

dialog::backdrop {
  background: rgba(0, 0, 0, .43);
}

.close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 1.7rem;
}

.detail-art {
  position: relative;
  width: 240px;
  height: 240px;
}

.detail-art img {
  display: block;
  width: 100%;
  height: 100%;
  opacity: 0;
  object-fit: contain;
  transition: opacity 160ms ease;
}

.detail-art.high-res-loaded img {
  opacity: 1;
}

dialog h2 {
  margin: 2px 0 0;
  font-size: 1.35rem;
}

.detail-korean {
  margin: 3px 0 14px;
  font-size: 1rem;
}

.detail-copy {
  margin: 0;
  color: #4f4f4f;
  font-size: .95rem;
  line-height: 1.5;
}

.load-error {
  grid-column: 1 / -1;
  padding: 50px;
  text-align: center;
}

@media (max-width: 600px) {
  header {
    padding: 10px 8px 12px;
  }

  .header-controls {
    gap: 4px;
  }

  .header-density,
  #grid-slider {
    width: 62px;
  }

  .header-density {
    flex-basis: 62px;
  }

  .header-password span,
  .header-group span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .header-password input,
  .header-group input {
    width: 68px;
  }

  h1 {
    font-size: .96rem;
  }

  select {
    width: 70px;
    min-width: 70px;
    padding-right: 18px;
  }

  main {
    padding: 3px 8px 16px;
  }

  .photo-controls {
    grid-template-columns: 1fr;
  }

  .photo-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .card {
    padding: 1px 2px 3px;
  }

  .food-art {
    width: min(122px, 100%);
    height: auto;
    aspect-ratio: 1;
  }

  .translated {
    font-size: clamp(.6rem, 3vw, .78rem);
  }

  .korean {
    font-size: clamp(.58rem, 2.7vw, .72rem);
  }

  .food-candidate.with-media {
    grid-template-columns: minmax(82px, 108px) minmax(0, 1fr);
  }

  .candidate-media {
    flex-basis: 92px;
    width: 92px;
    height: 92px;
  }

  .detail-art {
    width: 220px;
    height: 220px;
  }
}
