/* ─── TOKENS ─────────────────────────────────────────────────────────────── */
:root {
  --bg:            #eef4f8;
  --panel:         #ffffff;
  --panel-soft:    #f5f9fc;
  --line:          #dce8f2;
  --text:          #162d44;
  --text-soft:     #5f7a8f;
  --primary:       #0b4f99;
  --primary-dark:  #083d77;
  --primary-soft:  #eaf3ff;
  --danger:        #c0392b;
  --danger-soft:   #fdf1f0;
  --success:       #177a4e;
  --shadow-sm:     0 2px 8px rgba(16,40,70,0.08);
  --shadow-md:     0 6px 22px rgba(16,40,70,0.10);
  --shadow-lg:     0 12px 40px rgba(16,40,70,0.12);
  --r-sm:  10px;
  --r-md:  14px;
  --r-lg:  18px;
  --r-xl:  24px;
}

/* ─── RESET ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: "Segoe UI", system-ui, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

body { min-height: 100vh; }

/* ─── SHELL ──────────────────────────────────────────────────────────────── */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── HEADER ─────────────────────────────────────────────────────────────── */
.app-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 20px;
  padding: 18px 28px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header-center h1 {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.app-header-center p {
  margin: 4px 0 0;
  font-size: 0.9rem;
  color: var(--text-soft);
}

/* ─── MAIN LAYOUT ────────────────────────────────────────────────────────── */
.app-main {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 24px;
  padding: 24px;
  align-items: start;
  flex: 1;
}

/* ─── BUTTONS ─────────────────────────────────────────────────────────────── */
button {
  font: inherit;
  cursor: pointer;
  border: none;
  transition: all 0.17s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
  border-radius: var(--r-md);
  padding: 11px 20px;
  font-weight: 700;
  font-size: 0.92rem;
  box-shadow: 0 3px 10px rgba(11,79,153,0.22);
}
.primary-btn:hover:not(:disabled) {
  background: var(--primary-dark);
  box-shadow: 0 5px 16px rgba(11,79,153,0.28);
  transform: translateY(-1px);
}

.secondary-btn {
  background: #fff;
  color: var(--primary);
  border: 1.5px solid #c5d8ed;
  border-radius: var(--r-md);
  padding: 11px 20px;
  font-weight: 700;
  font-size: 0.92rem;
}
.secondary-btn:hover:not(:disabled) {
  background: var(--primary-soft);
  border-color: #a0c0e0;
}

.back-btn {
  background: #0b3060;
  color: #fff;
  border: none;
  border-radius: var(--r-md);
  padding: 10px 18px;
  font-weight: 700;
  font-size: 0.88rem;
  box-shadow: 0 3px 10px rgba(10, 40, 90, 0.22);
}
.back-btn:hover {
  background: #082448;
  box-shadow: 0 5px 16px rgba(10, 40, 90, 0.30);
  transform: translateY(-1px);
}

.add-btn {
  background: var(--primary-soft);
  color: var(--primary);
  border: 1.5px dashed #9ac0e6;
  border-radius: var(--r-md);
  padding: 10px 18px;
  font-weight: 700;
  font-size: 0.88rem;
  width: 100%;
  margin-top: 12px;
}
.add-btn:hover:not(:disabled) {
  background: #ddeeff;
  border-color: var(--primary);
}
.add-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Icon buttons */
.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  padding: 0;
  flex-shrink: 0;
}

.regen-btn {
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid #cde0f5;
}
.regen-btn:hover { background: #d0e8ff; }

.remove-btn {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #f2cac6;
}
.remove-btn:hover { background: #fce2df; }

/* ─── SETTINGS PANEL ─────────────────────────────────────────────────────── */
.settings-panel {
  position: sticky;
  top: 80px;
  max-height: calc(100vh - 104px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #c5d8ed transparent;
}

.settings-panel::-webkit-scrollbar { width: 5px; }
.settings-panel::-webkit-scrollbar-thumb { background: #c5d8ed; border-radius: 99px; }

.panel-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.panel-top-row h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: 99px;
  background: var(--primary);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
}

/* ─── CIRCLE CONFIG CARDS ────────────────────────────────────────────────── */
.circle-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
}

.circle-config-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow 0.15s;
}
.circle-config-card:hover {
  box-shadow: var(--shadow-md);
}

.circle-config-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px 11px;
  background: linear-gradient(to bottom, #f8fbfe, #f3f8fc);
  border-bottom: 1px solid #e6eef5;
  user-select: none;
}

.circle-header-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.circle-config-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: #1a3352;
}

.circle-config-summary {
  font-size: 0.8rem;
  color: var(--text-soft);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chevron-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}
.chevron-icon.open {
  transform: rotate(180deg);
}

.circle-config-body {
  /* shown/hidden via JS */
}

.circle-header-btns {
  display: flex;
  gap: 7px;
}

.cfg-form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 16px;
  border-bottom: 1px solid #eff4f8;
  gap: 12px;
}
.cfg-form-row:last-child { border-bottom: none; }

.cfg-label {
  font-weight: 600;
  font-size: 0.88rem;
  color: #2b4a65;
  flex-shrink: 0;
}

.cfg-select {
  font: inherit;
  font-size: 0.88rem;
  padding: 7px 10px;
  border: 1.5px solid #ccdce8;
  border-radius: var(--r-sm);
  background: #fff;
  color: var(--text);
  min-width: 0;
  max-width: 195px;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
  cursor: pointer;
}
.cfg-select:focus {
  outline: none;
  border-color: #7aaee0;
  box-shadow: 0 0 0 3px rgba(126,174,224,0.18);
}

/* ─── MESSAGE BOX ────────────────────────────────────────────────────────── */
.message-box {
  margin-top: 12px;
  padding: 13px 16px;
  background: #fff4f2;
  border: 1px solid #f1c2bd;
  border-radius: var(--r-md);
  color: #b42318;
  font-weight: 700;
  font-size: 0.9rem;
  box-shadow: var(--shadow-sm);
}

/* ─── PREVIEW PANEL ──────────────────────────────────────────────────────── */
.preview-panel { min-width: 0; }

.preview-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.preview-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid #e4edf5;
  background: linear-gradient(to bottom, #fcfeff, #f7fbfe);
}

.preview-card-header h2 {
  margin: 0;
  font-size: 1.2rem;
  color: #122b46;
}

.preview-card-header p {
  margin: 4px 0 0;
  font-size: 0.88rem;
  color: var(--text-soft);
}

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

.preview-card-body {
  padding: 20px;
  display: flex;
  justify-content: center;
}

.canvas-frame {
  width: 100%;
  background: linear-gradient(160deg, #f6fafd 0%, #eef4f8 100%);
  border: 1px solid #dce8f2;
  border-radius: var(--r-lg);
  padding: 18px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 420px;
  overflow: auto;
}

#mainCanvas {
  display: block;
  background: #fff;
  border: 1px solid #d2e2ef;
  border-radius: 14px;
  box-shadow: 0 6px 24px rgba(20,50,80,0.09);
  max-width: 100%;
  height: auto;
}

/* ─── RESPONSIVE ──────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .app-main { grid-template-columns: 340px minmax(0,1fr); }
}

@media (max-width: 860px) {
  .app-main { grid-template-columns: 1fr; padding: 16px; gap: 16px; }
  .settings-panel { position: static; max-height: none; }
  .app-header { grid-template-columns: 1fr; padding: 14px 16px; }
  .app-header-right { display: none; }
}

@media (max-width: 480px) {
  .preview-card-header { flex-direction: column; align-items: flex-start; }
  .canvas-frame { min-height: 300px; }
}

/* ─── INFO BUTTON ─────────────────────────────────────────────────────────── */
.info-btn {
  background: #1a8a4a;
  color: #fff;
  border: none;
  border-radius: var(--r-md);
  padding: 10px 18px;
  font-weight: 700;
  font-size: 0.92rem;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 3px 10px rgba(20, 120, 60, 0.25);
}
.info-btn:hover {
  background: #147040;
  box-shadow: 0 5px 16px rgba(20, 120, 60, 0.32);
  transform: translateY(-1px);
}

/* ─── MODAL ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 30, 50, 0.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal-box {
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(10, 30, 60, 0.22);
  width: 100%;
  max-width: 580px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(to bottom, #f8fbfe, #f3f7fc);
  flex-shrink: 0;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
  color: var(--text);
}

.modal-close-btn {
  background: #f0f4f8;
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--text-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.modal-close-btn:hover {
  background: #e4edf5;
  color: var(--text);
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: #c5d8ed transparent;
}

.modal-body::-webkit-scrollbar { width: 5px; }
.modal-body::-webkit-scrollbar-thumb { background: #c5d8ed; border-radius: 99px; }

.info-section {
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid #eef3f8;
}
.info-section:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.info-section h3 {
  margin: 0 0 7px;
  font-size: 0.97rem;
  color: var(--text);
}

.info-section p,
.info-section ul {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-soft);
  line-height: 1.6;
}

.info-section ul {
  padding-left: 18px;
}
.info-section ul li {
  margin-bottom: 4px;
}

.modal-footer {
  padding: 14px 24px 18px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  flex-shrink: 0;
}