* {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --bg: #f9f9fb;
  --panel: rgba(255, 255, 255, 0.9);
  --text: #0f0f10;
  --muted: #6d6d72;
  --accent: #0f0f10;
  --stroke: #e3e3e6;
  --top-height: 56px;
  --footer-height: 130px;
}

body {
  margin: 0;
  font-family: 'Inter', 'SF Pro Display', 'SF Pro Text', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.top-bar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.1px;
  color: var(--text);
  background: var(--panel);
  border-bottom: 1px solid var(--stroke);
}

.camera-shell {
  position: relative;
  flex: 0 0 auto;
  height: calc(100vh - var(--top-height) - var(--footer-height));
  min-height: 360px;
  overflow: hidden;
  background: #fff;
}

video,
canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

canvas {
  pointer-events: none;
}

.frame-guide {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  flex-direction: column;
  gap: 18px;
}

.frame-rect {
  width: 72vw;
  height: 42vh;
  max-width: 480px;
  max-height: 360px;
  border: 2px solid #ffffff;
}

.frame-text {
  font-size: 14px;
  letter-spacing: 0.2px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.78);
  padding: 6px 10px;
}

.tag-board {
  position: absolute;
  top: 12px;
  left: 12px;
  display: inline-flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  display: none;
}

.tag-board .tag {
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.88);
  color: #0f0f10;
  font-size: 13px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.bottom-bar {
  padding: 14px 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--panel);
  border-top: 1px solid var(--stroke);
  position: sticky;
  bottom: 0;
  z-index: 5;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

button {
  width: 100%;
  height: 56px;
  border: 1px solid var(--stroke);
  background: #0f0f10;
  color: #fdfdfd;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.1px;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.12s ease, color 0.12s ease, transform 0.08s ease;
}

button:active {
  background: #1f1f22;
  transform: translateY(1px);
}

.ghost {
  background: #ffffff;
  color: #0f0f10;
}

.status {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  min-height: 18px;
}

.form-panel {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 10;
  backdrop-filter: blur(4px);
}

.form-panel.hidden {
  display: none;
}

.form-card {
  width: min(720px, 100%);
  background: #ffffff;
  border: 1px solid var(--stroke);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 92vh;
}

.form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #0f0f10;
  font-weight: 600;
  font-size: 16px;
}

.form-msg {
  min-height: 18px;
  font-size: 13px;
  color: #b45309;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  background: #f5f5f7;
  color: #0f0f10;
  border: 1px solid var(--stroke);
  font-size: 18px;
  cursor: pointer;
}

.form-body {
  display: grid;
  gap: 12px;
  overflow-y: auto;
  padding-right: 2px;
}

.thumb {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 14px;
  align-items: center;
}

.thumb img {
  width: 140px;
  height: 140px;
  object-fit: cover;
  border: 1px solid var(--stroke);
  background: #f5f5f7;
}

.thumb-label {
  color: var(--muted);
  font-size: 13px;
}

.thumb + .gallery {
  margin-top: 8px;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.gallery .tile {
  position: relative;
  border: 1px solid var(--stroke);
  background: #f5f5f7;
  height: 100px;
  overflow: hidden;
}

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

.gallery .badge {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 12px;
  padding: 2px 6px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #0f0f10;
  font-size: 13px;
}

input {
  height: 44px;
  background: #f5f5f7;
  color: #0f0f10;
  border: 1px solid var(--stroke);
  padding: 0 10px;
  font-size: 14px;
}

input.invalid {
  border-color: #d14343;
  background: #ffecec;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  position: sticky;
  bottom: 0;
  background: #ffffff;
  padding-top: 8px;
}

.dialog {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 20;
}

.dialog.hidden {
  display: none;
}

.dialog-card {
  background: #fff;
  border: 1px solid var(--stroke);
  padding: 16px;
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dialog-title {
  font-weight: 700;
  color: #0f0f10;
}

.dialog-desc {
  color: var(--muted);
  font-size: 14px;
}

.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

@media (max-width: 600px) {
  .thumb {
    grid-template-columns: 1fr;
    align-items: flex-start;
  }
}

@media (max-height: 740px) {
  :root {
    --footer-height: 146px;
  }
  .camera-shell {
    min-height: 300px;
    height: calc(100vh - var(--top-height) - var(--footer-height));
  }
  .frame-rect {
    height: 34vh;
  }
}

@media (min-width: 768px) {
  .frame-rect {
    width: 520px;
    height: 360px;
  }
}
