:root {
  --bg: #f5f6f8;
  --card: #fff;
  --text: #1f2329;
  --muted: #646a73;
  --primary: #3370ff;
  --primary-pressed: #245bdb;
  --border: #dee0e3;
  --danger: #f54a45;
  --radius: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 2px 12px rgba(0,0,0,.06);
}

.login-card h1 { margin: 0 0 12px; font-size: 20px; }

#app {
  max-width: 720px;
  margin: 0 auto;
  padding-bottom: calc(16px + var(--safe-bottom));
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 16px 8px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1 { margin: 0; font-size: 18px; }
.subtitle { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.user-bar { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }

.tabs {
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
}

.tab {
  flex: 1;
  border: none;
  background: none;
  padding: 12px 8px;
  font-size: 14px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.panel { padding: 12px 16px 24px; }
.panel:not(.active) { display: none; }

.form fieldset {
  border: none;
  margin: 0 0 16px;
  padding: 16px;
  background: var(--card);
  border-radius: var(--radius);
}

legend {
  font-weight: 600;
  font-size: 14px;
  padding: 0;
  margin-bottom: 12px;
}

label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}

label input, label select, label textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

.row-2, .row-3 {
  display: grid;
  gap: 8px;
}
.row-2 { grid-template-columns: 1fr 1fr; }
.row-3 { grid-template-columns: 1fr 1fr 1fr; }

.file-field {
  margin-bottom: 12px;
}

.file-field-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.file-picker-wrap {
  position: relative;
  display: block;
}

.file-picker-btn {
  display: block;
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--primary);
  pointer-events: none;
}

.file-input-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
  font-size: 0;
}

.count-row {
  margin-top: 4px;
}

.count-field {
  margin-bottom: 0;
}

.count-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.stepper {
  display: flex;
  align-items: stretch;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.stepper-btn {
  flex: 0 0 48px;
  min-height: 48px;
  border: none;
  background: var(--bg);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.stepper-btn:active:not(:disabled) {
  background: #e8eaed;
}

.stepper-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.stepper-input {
  flex: 1;
  min-width: 0;
  margin: 0 !important;
  padding: 0 4px !important;
  border: none !important;
  border-left: 1px solid var(--border) !important;
  border-right: 1px solid var(--border) !important;
  border-radius: 0 !important;
  text-align: center;
  font-size: 17px !important;
  font-weight: 600;
  background: #fff !important;
  -moz-appearance: textfield;
  appearance: textfield;
}

.stepper-input::-webkit-outer-spin-button,
.stepper-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

@media (max-width: 520px) {
  .row-3 { grid-template-columns: 1fr; }
}

.hint { font-size: 12px; color: var(--muted); margin: 0 0 10px; }

.btn {
  border: none;
  border-radius: 8px;
  padding: 11px 16px;
  font-size: 15px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: inline-block;
}

.btn.block { width: 100%; margin-top: 8px; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:disabled { opacity: .45; }
.btn.secondary { background: #e8f0ff; color: var(--primary); }
.btn.tertiary { background: transparent; color: var(--primary); font-size: 13px; padding: 6px 0; }
.btn.text { background: none; color: var(--muted); padding: 4px 8px; font-size: 13px; }

details { margin: 12px 0; }
details summary { cursor: pointer; font-weight: 500; font-size: 14px; }

.prompt-box { margin-bottom: 10px; }
.prompt-box textarea {
  width: 100%;
  min-height: 72px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}

.thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.thumbs.ref-preview {
  margin-top: 4px;
}

.ref-hint {
  margin: 8px 0 0;
}

.thumb-item {
  position: relative;
}

.thumb-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: zoom-in;
  display: block;
}

.thumbs .cap { font-size: 11px; color: var(--muted); text-align: center; margin-top: 4px; }

.thumb-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.thumb-del:active {
  background: var(--danger);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

.lightbox-close {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: 12px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.note-preview {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
  max-height: 50vh;
  overflow: auto;
  font-size: 14px;
  line-height: 1.7;
}

.note-preview img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  cursor: zoom-in;
}

#btn-copy-note {
  margin-top: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(0,0,0,.78);
  color: #fff;
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 100;
  max-width: 90vw;
}

.loading {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
