/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #1565c0;
  --primary-light: #42a5f5;
  --accent: #ff6f00;
  --accent-light: #ffca28;
  --bg-dark: #0d1b2a;
  --bg-mid: #1a2f45;
  --text: #e8f4fd;
  --text-muted: #90b8d4;
  --card-bg: rgba(255, 255, 255, 0.07);
  --card-border: rgba(255, 255, 255, 0.12);
  --radius: 16px;
  --radius-sm: 10px;
}

html, body {
  height: 100%;
}

body {
  font-family: 'Hiragino Sans', 'Noto Sans JP', 'Meiryo', sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

[x-cloak] { display: none !important; }

/* ===== Main App ===== */
.app-container {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Header --- */
.app-header {
  background: linear-gradient(135deg, #0a2744 0%, #1565c0 100%);
  padding: 14px 16px 10px;
  border-bottom: 2px solid var(--primary-light);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
}

.header-icon {
  font-size: 1.4rem;
  line-height: 1;
}

.app-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #e3f2fd;
}

.stamp-progress {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 10px;
}

.progress-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  border: 1px solid rgba(255,255,255,0.4);
  transition: background 0.3s;
}

.progress-dot.active {
  background: var(--accent-light);
  border-color: var(--accent-light);
  box-shadow: 0 0 6px var(--accent-light);
}

/* --- Canvas section --- */
.canvas-section {
  flex-shrink: 0;
  background: #000;
  width: 100%;
}

.canvas-frame {
  position: relative;
  width: 100%;
  background: #000;
  overflow: hidden;
}

#displayCanvas {
  width: 100%;
  height: auto;
  display: block;
}


/* --- New stamp badge --- */
.new-stamp-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255, 111, 0, 0.92);
  border-radius: 10px;
  padding: 4px 8px;
  box-shadow: 0 2px 8px rgba(255,111,0,0.5);
  animation: badge-pop 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes badge-pop {
  0%   { transform: scale(0.3) rotate(-10deg); opacity: 0; }
  70%  { transform: scale(1.1) rotate(3deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.badge-text {
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: #fff;
}

.badge-num {
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
}

/* --- Loading overlay --- */
.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(10, 20, 35, 0.8);
  gap: 14px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255,255,255,0.15);
  border-top-color: var(--primary-light);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* --- Action section --- */
.action-section {
  flex: 1;
  padding: 16px;
}

/* Stamp info card */
.stamp-info-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
}

.stamp-info-icon {
  font-size: 2rem;
  line-height: 1;
  flex-shrink: 0;
}

.stamp-info-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-light);
  margin-bottom: 2px;
}

.stamp-info-sub {
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Save button */
.btn-save {
  width: 100%;
  padding: 18px;
  background: linear-gradient(135deg, var(--accent) 0%, #ff8f00 100%);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  letter-spacing: 0.06em;
  box-shadow: 0 5px 18px rgba(255,111,0,0.45);
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-save:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 7px 22px rgba(255,111,0,0.55);
}

.btn-save:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 3px 10px rgba(255,111,0,0.4);
}

.btn-save:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.saving-text {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.save-guide-wrap {
  margin-top: 10px;
  text-align: center;
}

.save-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.7;
}

.save-guide-msg {
  font-size: 0.82rem;
  color: #6ee7b7;
  line-height: 1.7;
  padding: 8px 12px;
  background: rgba(52, 211, 153, 0.1);
  border-radius: 8px;
  border: 1px solid rgba(52, 211, 153, 0.25);
}

/* Hint card */
.hint-card {
  background: var(--card-bg);
  border: 1px dashed var(--card-border);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
}

.hint-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  line-height: 1;
}

.hint-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary-light);
  margin-bottom: 10px;
}

.hint-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.9;
  margin-bottom: 20px;
}

.hint-stamps {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.hint-stamp-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.hint-stamp-icon {
  font-size: 1.2rem;
  opacity: 0.4;
}

.hint-stamp-label {
  font-size: 0.68rem;
  color: var(--text-muted);
}

/* Progress label */
.progress-label {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Complete overlay（暗転なし） */
.complete-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  pointer-events: none;
}

/* Confetti canvas */
.confetti-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.complete-inner {
  text-align: center;
  animation: complete-pop 0.6s cubic-bezier(0.36, 0.07, 0.19, 0.97);
  position: relative;
  z-index: 11;
}

.complete-emoji {
  font-size: 3.5rem;
  line-height: 1.2;
}

.complete-title {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--accent-light);
  text-shadow: 0 0 12px rgba(0,0,0,0.9), 0 2px 4px rgba(0,0,0,0.9);
}

.complete-sub {
  font-size: 1rem;
  color: #fff;
  text-shadow: 0 0 8px rgba(0,0,0,0.9), 0 1px 3px rgba(0,0,0,0.9);
}

@keyframes complete-pop {
  0%   { transform: scale(0.4); opacity: 0; }
  70%  { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}

/* Hint URL example */
.hint-url-example {
  background: rgba(255,255,255,0.06);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 16px;
  text-align: left;
}

.hint-url-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.hint-url-code {
  font-family: monospace;
  font-size: 0.75rem;
  color: #93c5fd;
  word-break: break-all;
}

/* New arrival card */
.new-arrival-card {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 202, 40, 0.12);
  border: 1px solid rgba(255, 202, 40, 0.35);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 14px;
  animation: badge-pop 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

.new-arrival-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
}

.new-arrival-text {
  font-size: 0.88rem;
  color: var(--accent-light);
  font-weight: 600;
}

/* Reset area */
.reset-area {
  margin-top: 14px;
  text-align: center;
}

.btn-reset {
  background: none;
  border: 1px solid rgba(255,255,255,0.2);
  color: var(--text-muted);
  font-size: 0.82rem;
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.btn-reset:hover {
  border-color: #f87171;
  color: #f87171;
}

.reset-confirm {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.reset-confirm p {
  font-size: 0.88rem;
  color: #fca5a5;
  margin-bottom: 10px;
}

.reset-confirm-btns {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.btn-reset-yes {
  padding: 7px 16px;
  background: #ef4444;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-reset-no {
  padding: 7px 16px;
  background: rgba(255,255,255,0.1);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
}

/* iOS 長押し保存モーダル */
.preview-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.preview-modal-inner {
  background: #1a2f45;
  border-radius: var(--radius);
  padding: 20px 16px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  border: 1px solid rgba(255,255,255,0.15);
}

.preview-instruction {
  font-size: 1rem;
  color: var(--accent-light);
  text-align: center;
  line-height: 1.8;
}

.preview-img {
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.2);
  display: block;
  /* ユーザーが長押しできるよう選択を許可 */
  -webkit-user-select: auto;
  user-select: auto;
  -webkit-touch-callout: default;
}

.preview-close {
  padding: 10px 32px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 20px;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 180, 100, 0.95);
  color: #fff;
  padding: 12px 24px;
  border-radius: 30px;
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
  white-space: nowrap;
  z-index: 9999;
}


/* ===== Admin styles ===== */
.admin-body {
  background: #111827;
}

.admin-container {
  max-width: 900px;
  margin: 0 auto;
  padding-bottom: 40px;
}

.admin-header {
  background: linear-gradient(135deg, #111827, #1e3a5f);
  border-bottom: 2px solid #2563eb;
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.admin-header-inner {
  display: flex;
  align-items: center;
  gap: 16px;
}
.admin-logout-btn {
  margin-left: auto;
  padding: 6px 14px;
  border-radius: 8px;
  background: rgba(239,68,68,0.15);
  border: 1px solid rgba(239,68,68,0.35);
  color: #fca5a5;
  font-size: 0.82rem;
  text-decoration: none;
  transition: background 0.2s;
}
.admin-logout-btn:hover {
  background: rgba(239,68,68,0.28);
}

.admin-back-link {
  color: #93c5fd;
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 0.2s;
}

.admin-back-link:hover {
  color: #bfdbfe;
}

.admin-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: #e0f2fe;
}

.admin-content {
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.admin-section {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 24px;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #93c5fd;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.section-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 16px;
  line-height: 1.7;
}

/* Background preview */
.bg-preview-area {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.bg-img-wrap {
  position: relative;
  flex-shrink: 0;
  width: 100%;
  max-width: 360px;
}

.bg-preview-img {
  width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  display: block;
  border: 2px solid rgba(255,255,255,0.15);
}

.position-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 22px;
  height: 22px;
  background: rgba(255, 111, 0, 0.9);
  border: 2px solid #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
}

.marker-num {
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  line-height: 1;
}

.bg-controls {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-start;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text-muted);
  cursor: pointer;
}

.upload-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.file-label {
  display: block;
  cursor: pointer;
}

.file-label input[type="file"] {
  display: none;
}

.file-btn {
  display: inline-block;
  padding: 8px 14px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s;
}

.file-btn:hover {
  background: rgba(255,255,255,0.14);
}

.btn-upload {
  padding: 10px 18px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-upload:hover {
  background: #1d4ed8;
}

/* Stamp size */
.stampsize-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stampsize-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.stampsize-slider {
  flex: 1;
  height: 6px;
  accent-color: var(--primary-light);
  cursor: pointer;
}

.stampsize-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent-light);
  min-width: 52px;
  text-align: right;
}

.stampsize-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Positions form */
.positions-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.positions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.position-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.05);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}

.pos-num {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--accent-light);
  width: 36px;
  flex-shrink: 0;
}

.pos-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.pos-input {
  width: 64px;
  padding: 4px 6px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.85rem;
  text-align: right;
}

.pos-input:focus {
  outline: none;
  border-color: var(--primary-light);
}

.btn-positions {
  align-self: flex-start;
  padding: 10px 24px;
  background: #059669;
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-positions:hover {
  background: #047857;
}

/* Stamps grid */
.stamps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

.stamp-admin-card {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stamp-admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stamp-admin-num {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary-light);
}

.stamp-status-ok {
  font-size: 0.75rem;
  color: #34d399;
  font-weight: 600;
}

.stamp-status-ng {
  font-size: 0.75rem;
  color: #f87171;
  font-weight: 600;
}

.stamp-admin-preview {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 80px;
  background: rgba(255,255,255,0.04);
  border-radius: 8px;
  overflow: hidden;
}

.stamp-thumb {
  max-width: 100%;
  max-height: 80px;
  object-fit: contain;
}

.stamp-empty {
  width: 60px;
  height: 60px;
  border: 2px dashed rgba(255,255,255,0.2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: rgba(255,255,255,0.2);
}

.stamp-admin-link {
  font-size: 0.75rem;
}

.qr-url-label {
  color: var(--text-muted);
  margin-bottom: 2px;
}

.qr-url {
  font-family: monospace;
  font-size: 0.72rem;
  background: rgba(255,255,255,0.08);
  padding: 2px 6px;
  border-radius: 4px;
  color: #93c5fd;
  word-break: break-all;
}

.stamp-upload-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.file-label-sm {
  display: block;
  cursor: pointer;
}

.file-label-sm input[type="file"] {
  display: none;
}

.file-btn-sm {
  display: inline-block;
  padding: 5px 10px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s;
  width: 100%;
  text-align: center;
}

.file-btn-sm:hover {
  background: rgba(255,255,255,0.12);
}

.btn-stamp-upload {
  width: 100%;
  padding: 7px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-stamp-upload:hover {
  background: #1d4ed8;
}

/* QR guide */
.qr-guide {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 8px;
}
.qr-guide:last-child {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 0;
}

.qr-guide-subtitle {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent-light);
  margin: 0;
}

.qr-format {
  display: inline-block;
  margin-top: 6px;
  font-family: monospace;
  font-size: 0.82rem;
  background: rgba(255,255,255,0.08);
  padding: 6px 10px;
  border-radius: 6px;
  color: #a5f3fc;
  word-break: break-all;
}

.qr-examples {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 6px;
}

.qr-example-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.04);
  border-radius: 6px;
  padding: 6px 10px;
}

.qr-ex-num {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent-light);
  width: 34px;
  flex-shrink: 0;
}

.qr-ex-url {
  font-family: monospace;
  font-size: 0.78rem;
  color: #93c5fd;
}
