:root{
  --bg:#f3f6fb;
  --card:#ffffff;
  --text:#111827;
  --muted:#6b7280;
  --line:#e5e7eb;
  --primary:#2563eb;
  --primary-dark:#1d4ed8;
  --shadow:0 10px 30px rgba(15,23,42,0.08);
  --danger:#b91c1c;
  --success:#15803d;
  --success-bg:#edf9f1;
}

*{
  box-sizing:border-box;
  margin:0;
  padding:0;
  -webkit-tap-highlight-color:transparent;
  font-family:Arial,sans-serif;
}

html, body{
  width:100%;
  min-height:100%;
  background:var(--bg);
  color:var(--text);
}

body{
  font-size:16px;
}

.app-shell{
  max-width:520px;
  min-height:100dvh;
  margin:0 auto;
  background:var(--bg);
}

.topbar{
  position:sticky;
  top:0;
  z-index:20;
  padding:env(safe-area-inset-top) 0 0 0;
  background:linear-gradient(135deg,#0f172a,#111827 65%,#1f2937);
  border-bottom-left-radius:22px;
  border-bottom-right-radius:22px;
  box-shadow:0 8px 24px rgba(15,23,42,0.18);
}

.topbar-inner{
  padding:16px 16px 18px;
}

.eyebrow{
  font-size:11px;
  font-weight:700;
  letter-spacing:.08em;
  text-transform:uppercase;
  color:#93c5fd;
  margin-bottom:6px;
}

.topbar h1{
  font-size:24px;
  color:#fff;
  margin-bottom:4px;
}

.topbar p{
  font-size:14px;
  color:#d1d5db;
  line-height:1.45;
}

.content{
  padding:14px 12px 120px;
}

.progress-card{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:18px;
  box-shadow:var(--shadow);
  padding:14px;
  margin-bottom:12px;
}

.progress-head{
  display:flex;
  justify-content:space-between;
  gap:10px;
  font-size:13px;
  color:var(--muted);
  margin-bottom:10px;
}

.progress-bar{
  width:100%;
  height:10px;
  background:#e8eef7;
  border-radius:999px;
  overflow:hidden;
}

.progress-bar-fill{
  width:25%;
  height:100%;
  background:linear-gradient(135deg,var(--primary),var(--primary-dark));
  border-radius:999px;
  transition:width .25s ease;
}

.section-card{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:20px;
  box-shadow:var(--shadow);
  padding:16px;
  margin-bottom:12px;
}

.card-title-row{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  margin-bottom:14px;
}

.card-title-row h2{
  font-size:19px;
}

.badge{
  padding:6px 10px;
  border-radius:999px;
  background:#eaf2ff;
  color:#1d4ed8;
  font-size:12px;
  font-weight:700;
  white-space:nowrap;
}

.badge.muted{
  background:#f3f4f6;
  color:#6b7280;
}

.field-group{
  display:flex;
  flex-direction:column;
  gap:8px;
  margin-bottom:14px;
}

.field-group:last-child{
  margin-bottom:0;
}

label{
  font-size:14px;
  font-weight:700;
}

input,
textarea{
  width:100%;
  border:1px solid #d7deea;
  border-radius:16px;
  padding:15px 14px;
  font-size:16px;
  outline:none;
  background:#fff;
  color:var(--text);
  transition:border-color .2s, box-shadow .2s;
}

input::placeholder,
textarea::placeholder{
  color:#9aa3af;
}

input:focus,
textarea:focus{
  border-color:var(--primary);
  box-shadow:0 0 0 4px rgba(37,99,235,0.10);
}

textarea{
  min-height:130px;
  resize:vertical;
  line-height:1.55;
}

.helper{
  font-size:12px;
  color:var(--muted);
  line-height:1.45;
}

.field-error{
  min-height:16px;
  font-size:12px;
  color:var(--danger);
}

.topics-grid{
  display:grid;
  grid-template-columns:1fr;
  gap:10px;
}

.topic-chip{
  display:flex;
  align-items:center;
  gap:12px;
  border:1px solid var(--line);
  border-radius:16px;
  padding:14px 16px;
  background:#fff;
  cursor:pointer;
  transition:.2s ease;
  min-height:58px;
  position:relative;
}

.topic-chip:hover{
  border-color:#bfd4ff;
  background:#f8fbff;
}

.topic-chip input{
  margin:0;
  flex:0 0 auto;
  width:18px;
  height:18px;
  accent-color:var(--primary);
}

.topic-chip span{
  font-size:14px;
  font-weight:700;
  line-height:1.35;
  display:block;
  flex:1;
  word-break:break-word;
}

.topic-chip.active{
  background:#eef4ff;
  border-color:#90b6ff;
  box-shadow:0 0 0 3px rgba(37,99,235,0.08);
}

.topic-chip.active span{
  color:#1d4ed8;
}

.hints-box{
  margin-top:14px;
  background:#eef4ff;
  border:1px solid #d6e4ff;
  border-radius:16px;
  padding:14px 16px;
  color:#334155;
  line-height:1.6;
  font-size:14px;
}

.hints-box b{
  display:block;
  margin-bottom:8px;
  color:#1d4ed8;
}

.inline-actions{
  margin-top:6px;
}

.ghost-btn{
  width:100%;
  border:none;
  border-radius:14px;
  padding:14px 16px;
  font-size:15px;
  font-weight:800;
  cursor:pointer;
  background:#e8eef7;
  color:#111827;
  transition:transform .12s ease, box-shadow .2s ease, background .2s ease, filter .2s ease;
}

.ghost-btn:hover,
.ghost-btn:focus-visible{
  background:#dfe8f5;
  box-shadow:0 8px 18px rgba(15,23,42,0.08);
}

.ghost-btn:active{
  transform:scale(.985);
}

.analyze-note{
  margin-top:8px;
  font-size:12px;
  line-height:1.45;
  color:var(--muted);
  padding:0 2px;
}

.analysis-box{
  margin-top:14px;
  background:#fffaf0;
  border:2px solid #ead39a;
  border-radius:18px;
  padding:16px;
  box-shadow:0 10px 24px rgba(15,23,42,0.04);
  color:#374151;
  line-height:1.65;
}

.analysis-box-title{
  font-weight:900;
  font-size:20px;
  color:#8a5a12;
  margin-bottom:10px;
}

.loader-inline{
  display:inline-flex;
  align-items:center;
  gap:10px;
}

.loader-inline-spinner{
  width:18px;
  height:18px;
  border:3px solid rgba(37,99,235,.18);
  border-top-color:#2563eb;
  border-radius:50%;
  animation:spin .8s linear infinite;
}

.photo-preview-grid{
  display:grid;
  grid-template-columns:repeat(2,1fr);
  gap:10px;
  margin-top:12px;
}

.photo-preview-item{
  background:#fff;
  border:1px solid var(--line);
  border-radius:16px;
  overflow:hidden;
  position:relative;
}

.photo-preview-item img{
  display:block;
  width:100%;
  height:120px;
  object-fit:cover;
}

.photo-remove-btn{
  position:absolute;
  top:8px;
  right:8px;
  width:30px;
  height:30px;
  border:none;
  border-radius:999px;
  background:rgba(17,24,39,0.86);
  color:#fff;
  font-size:18px;
  line-height:1;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
}

.photo-name{
  padding:8px 10px 10px;
  font-size:11px;
  color:#475569;
  line-height:1.35;
  word-break:break-word;
}

.bottom-action{
  position:fixed;
  left:0;
  right:0;
  bottom:0;
  z-index:30;
  max-width:520px;
  margin:0 auto;
  background:rgba(255,255,255,0.96);
  backdrop-filter:blur(10px);
  border-top:1px solid var(--line);
  padding:10px 12px calc(12px + env(safe-area-inset-bottom));
  box-shadow:0 -8px 24px rgba(15,23,42,0.08);
}

.status-box{
  min-height:20px;
  margin-bottom:10px;
  font-size:14px;
  font-weight:800;
  color:#374151;
  display:flex;
  align-items:center;
  gap:10px;
  line-height:1.4;
}

.status-loading{
  color:#1d4ed8;
  background:#eef4ff;
  border:1px solid #d6e4ff;
  border-radius:12px;
  padding:10px 12px;
}

.status-error{
  color:#b91c1c;
  background:#fef2f2;
  border:1px solid #fecaca;
  border-radius:12px;
  padding:10px 12px;
}

.status-success{
  color:#15803d;
  background:#edf9f1;
  border:1px solid #bbf7d0;
  border-radius:12px;
  padding:10px 12px;
}

.status-spinner{
  width:16px;
  height:16px;
  border:3px solid rgba(37,99,235,.18);
  border-top-color:#2563eb;
  border-radius:50%;
  animation:spin .8s linear infinite;
  flex:0 0 auto;
}

.primary-btn,
.secondary-btn{
  width:100%;
  border:none;
  border-radius:16px;
  padding:16px;
  font-size:16px;
  font-weight:800;
  cursor:pointer;
}

.primary-btn{
  color:#fff;
  background:linear-gradient(135deg,var(--primary),var(--primary-dark));
  box-shadow:0 12px 24px rgba(37,99,235,0.22);
  transition:transform .12s ease, box-shadow .2s ease, filter .2s ease;
}

.primary-btn:hover,
.primary-btn:focus-visible{
  filter:brightness(1.06);
  box-shadow:0 16px 28px rgba(37,99,235,0.28);
}

.primary-btn:active{
  transform:scale(.985);
  filter:brightness(1.02);
}

.primary-btn:disabled{
  opacity:.72;
  cursor:not-allowed;
  box-shadow:none;
  filter:grayscale(.08);
}

.secondary-btn{
  background:#111827;
  color:#fff;
}

.success-overlay{
  position:fixed;
  inset:0;
  display:none;
  align-items:center;
  justify-content:center;
  background:rgba(15,23,42,0.56);
  backdrop-filter:blur(4px);
  padding:20px;
  z-index:100;
}

.success-overlay.show{
  display:flex;
}

.success-card{
  width:100%;
  max-width:420px;
  background:#fff;
  border-radius:24px;
  padding:28px 20px 20px;
  box-shadow:0 24px 60px rgba(0,0,0,.18);
  text-align:center;
  animation:successCardIn .28s ease;
}

.success-icon-wrap{
  position:relative;
  width:86px;
  height:86px;
  margin:0 auto 16px;
}

.success-ring{
  position:absolute;
  inset:0;
  border-radius:999px;
  background:radial-gradient(circle, rgba(21,128,61,0.12) 0%, rgba(21,128,61,0.02) 70%, transparent 72%);
  animation:pulseRing 1.6s ease-in-out infinite;
}

.success-icon{
  position:relative;
  width:72px;
  height:72px;
  margin:7px auto 0;
  border-radius:999px;
  display:flex;
  align-items:center;
  justify-content:center;
  background:var(--success-bg);
  color:var(--success);
  font-size:38px;
  font-weight:900;
}

.success-card h3{
  font-size:26px;
  margin-bottom:10px;
}

.success-card p{
  color:#4b5563;
  line-height:1.6;
  margin-bottom:16px;
}

.success-actions{
  display:flex;
  flex-direction:column;
  gap:10px;
}

@keyframes successCardIn{
  from{
    opacity:0;
    transform:translateY(18px) scale(.96);
  }
  to{
    opacity:1;
    transform:translateY(0) scale(1);
  }
}

@keyframes spin{
  to{
    transform:rotate(360deg);
  }
}

@keyframes pulseRing{
  0%, 100%{
    transform:scale(.96);
    opacity:.8;
  }
  50%{
    transform:scale(1.06);
    opacity:1;
  }
}

@media (min-width:768px){
  body{
    padding:24px;
  }

  .app-shell{
    border-radius:28px;
    overflow:hidden;
    box-shadow:0 18px 40px rgba(15,23,42,0.10);
  }

  .bottom-action{
    border-bottom-left-radius:24px;
    border-bottom-right-radius:24px;
  }

  .photo-preview-grid{
    grid-template-columns:repeat(3,1fr);
  }

  .topics-grid{
    grid-template-columns:1fr 1fr;
  }
}
