/* Kieru - iPhone-like Modern UI */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --safe-top: env(safe-area-inset-top, 44px);
  --safe-bottom: env(safe-area-inset-bottom, 34px);
  --accent: #0a84ff;
  --green: #34c759;
  --red: #ff3b30;
  --orange: #ff9f0a;
  --bg: #000;
  --surface: rgba(28, 28, 30, 0.92);
  --surface2: rgba(44, 44, 46, 0.85);
  --text: #fff;
  --text-secondary: rgba(255,255,255,0.6);
  --border: rgba(255,255,255,0.12);
  --pill-bg: rgba(255,255,255,0.12);
  --pill-active: #0a84ff;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, 'SF Pro Display', 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

/* ─── Views ─────────────────────────────────────────── */
.view {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease, transform 0.28s ease;
  transform: translateX(30px);
}

.view.active {
  opacity: 1;
  pointer-events: all;
  transform: translateX(0);
}

/* ─── Camera View ─────────────────────────────────────── */
.camera-container {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
}

#camera-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Top Bar */
.camera-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: calc(var(--safe-top) + 8px) 20px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(to bottom, rgba(0,0,0,0.6) 0%, transparent 100%);
  z-index: 10;
}

.app-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

.app-icon {
  font-size: 20px;
}

.gallery-btn {
  position: relative;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
}
.gallery-btn:active { opacity: 0.6; }

.count-badge {
  position: absolute;
  top: 0;
  right: 0;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 1.5px solid #000;
}

/* Expiry Selector */
.expiry-selector {
  position: absolute;
  bottom: 160px;
  left: 0;
  right: 0;
  padding: 0 16px;
  z-index: 10;
}

.expiry-label {
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: rgba(255,255,255,0.7);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 10px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

.expiry-pills {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.expiry-pills::-webkit-scrollbar { display: none; }

.pill {
  flex-shrink: 0;
  background: rgba(0,0,0,0.4);
  border: 1.5px solid rgba(255,255,255,0.3);
  color: rgba(255,255,255,0.9);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.pill.active {
  background: var(--pill-active);
  border-color: var(--pill-active);
  color: #fff;
  box-shadow: 0 0 12px rgba(10,132,255,0.5);
}

.pill:active:not(.active) {
  background: rgba(255,255,255,0.2);
}

/* Camera Bottom */
.camera-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding-bottom: calc(var(--safe-bottom) + 16px);
  background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, transparent 100%);
  z-index: 10;
}

.camera-controls {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 20px 30px 10px;
}

.placeholder-btn {
  width: 52px;
  height: 52px;
}

/* Shutter Button */
.shutter-btn {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.85);
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease;
  padding: 0;
}

.shutter-inner {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(255,255,255,0.9);
  transition: transform 0.1s ease, background 0.1s;
}

.shutter-btn.shutter-press .shutter-inner {
  transform: scale(0.87);
  background: rgba(255,255,255,0.6);
}

.flip-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: transform 0.3s ease, opacity 0.15s;
}
.flip-btn:active { opacity: 0.6; }

/* Flash Overlay */
.flash-overlay {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 100;
  transition: opacity 0.05s ease;
}
.flash-overlay.flash-active {
  animation: flash 0.3s ease-out forwards;
}
@keyframes flash {
  0% { opacity: 0.9; }
  100% { opacity: 0; }
}

/* Permission Overlay */
.permission-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.permission-content {
  text-align: center;
  padding: 40px 30px;
  max-width: 320px;
}

.permission-icon {
  font-size: 60px;
  margin-bottom: 20px;
}

.permission-content h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 12px;
  letter-spacing: -0.3px;
}

.permission-content p {
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 28px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 14px 32px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:active { opacity: 0.75; }

/* ─── Gallery View ─────────────────────────────────── */
.gallery-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #000;
}

.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 8px) 16px 14px;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 0.5px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.gallery-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.back-btn, .delete-all-btn, .delete-photo-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
  color: var(--accent);
}
.back-btn:active, .delete-all-btn:active, .delete-photo-btn:active { opacity: 0.6; }

.delete-all-btn svg, .delete-photo-btn svg {
  stroke: var(--red);
}

.gallery-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-secondary);
}

.empty-icon {
  font-size: 56px;
  margin-bottom: 8px;
  opacity: 0.5;
}

.gallery-empty p {
  font-size: 17px;
  font-weight: 500;
}

.empty-sub {
  font-size: 14px !important;
  font-weight: 400 !important;
  opacity: 0.6;
}

/* Photo Grid */
.photo-grid {
  flex: 1;
  overflow-y: auto;
  padding: 2px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  align-content: start;
  -webkit-overflow-scrolling: touch;
}

.photo-card {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  cursor: pointer;
  background: #111;
}

.photo-thumb-wrap {
  position: relative;
  width: 100%;
  height: 100%;
}

.photo-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s;
}

.photo-card:active .photo-thumb {
  transform: scale(0.95);
}

.photo-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, transparent 50%, rgba(0,0,0,0.7) 100%);
}

.photo-card-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 6px 6px 5px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-timer {
  font-size: 11px;
  font-weight: 700;
  color: rgba(255,255,255,0.9);
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  letter-spacing: 0.2px;
}

.photo-card-footer.urgent .card-timer {
  color: #ff6b6b;
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* ─── Detail View ─────────────────────────────────── */
.detail-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #000;
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 8px) 16px 14px;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 0.5px solid var(--border);
  z-index: 10;
}

.detail-timer {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--green);
}

.detail-timer.urgent {
  color: var(--red);
  animation: pulse 1s ease-in-out infinite;
}

.detail-image-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000;
}

#detail-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.detail-footer {
  padding: 16px 20px calc(var(--safe-bottom) + 16px);
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 0.5px solid var(--border);
}

.expiry-bar-wrap {
  height: 4px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 10px;
}

.expiry-bar {
  height: 100%;
  border-radius: 2px;
  transition: width 1s linear;
}

.detail-info {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  letter-spacing: 0.1px;
}

/* ─── Toast ──────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 80px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(30,30,32,0.92);
  color: #fff;
  padding: 12px 22px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 0.5px solid var(--border);
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 1000;
  white-space: nowrap;
  max-width: 80vw;
  text-align: center;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── Modal ──────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: calc(var(--safe-bottom) + 12px);
  z-index: 200;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 24px 20px 16px;
  width: calc(100% - 32px);
  max-width: 400px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 0.5px solid var(--border);
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-message {
  font-size: 16px;
  font-weight: 500;
  text-align: center;
  margin-bottom: 20px;
  color: var(--text);
  line-height: 1.4;
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-cancel, .modal-confirm {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.modal-cancel {
  background: rgba(255,255,255,0.1);
  color: var(--text);
}

.modal-confirm {
  background: var(--red);
  color: #fff;
}

.modal-cancel:active, .modal-confirm:active { opacity: 0.75; }

/* ─── Extend Expiry Section ───────────────────────── */
.extend-section {
  margin-top: 14px;
  border-top: 0.5px solid var(--border);
  padding-top: 14px;
}

.extend-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: center;
  margin-bottom: 10px;
}

.extend-pills {
  display: flex;
  gap: 7px;
  justify-content: center;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.extend-pills::-webkit-scrollbar { display: none; }

.extend-pill {
  flex-shrink: 0;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.9);
  border-radius: 20px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.extend-pill:active {
  background: rgba(255,255,255,0.25);
  transform: scale(0.95);
}

.extend-pill-forever {
  background: rgba(10, 132, 255, 0.2);
  border-color: rgba(10, 132, 255, 0.6);
  color: #5ac8fa;
}

.extend-pill-forever:active {
  background: rgba(10, 132, 255, 0.35);
}

/* 無期限タイマー表示 */
.detail-timer.forever {
  color: #5ac8fa;
  animation: none;
}

/* ギャラリーカード：無期限 */
.photo-card-footer.forever .card-timer {
  color: #5ac8fa;
  font-size: 13px;
}

/* ─── PWA Install Banner ──────────────────────────── */
.pwa-banner {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(0);
  width: calc(100% - 32px);
  max-width: 380px;
  z-index: 500;
  animation: slideUpBanner 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.pwa-banner.hiding {
  animation: slideDownBanner 0.35s ease forwards;
}

@keyframes slideUpBanner {
  from { opacity: 0; transform: translateX(-50%) translateY(30px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes slideDownBanner {
  from { opacity: 1; transform: translateX(-50%) translateY(0); }
  to   { opacity: 0; transform: translateX(-50%) translateY(30px); }
}

.pwa-banner-inner {
  background: rgba(30, 30, 32, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 0.5px solid rgba(255,255,255,0.15);
  border-radius: 18px;
  padding: 14px 14px 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.pwa-banner-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  flex-shrink: 0;
}

.pwa-banner-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.pwa-banner-text strong {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
}

.pwa-banner-text span {
  font-size: 12px;
  color: rgba(255,255,255,0.65);
  line-height: 1.4;
}

.pwa-banner-close {
  background: rgba(255,255,255,0.1);
  border: none;
  color: rgba(255,255,255,0.6);
  font-size: 13px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.pwa-banner-close:active { background: rgba(255,255,255,0.2); }

.pwa-banner-arrow {
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 10px solid rgba(30, 30, 32, 0.96);
  margin: 0 auto;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

/* ─── Utilities ───────────────────────────────────── */
.hidden {
  display: none !important;
}

/* Scrollbar */
::-webkit-scrollbar { display: none; }
* { scrollbar-width: none; }

/* Selection */
::selection { background: transparent; }
