:root {
  --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out-quint: cubic-bezier(0.22, 1, 0.36, 1);
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: #FAF9F8; }
body { font-family: 'Prompt', sans-serif; color: #1C1917; }
body.lang-en { font-family: 'Noto Sans', sans-serif; }

/* Noise texture overlay */
.noise::after {
  content: '';
  position: absolute; inset: 0; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  opacity: 0.06; border-radius: inherit;
}

#app {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  background: #FAF9F8;
}

.page { display: none; min-height: 100vh; padding-bottom: 80px; }
.page.active { display: block; }

/* Header gradient */
.page-header {
  background: linear-gradient(135deg, #C4400F 0%, #A33510 50%, #7A2200 100%);
  position: relative; overflow: hidden;
  padding: 20px 20px 28px;
}
.page-header::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 180px; height: 180px;
  background: radial-gradient(circle, rgba(255,255,255,0.12) 0%, transparent 70%);
  border-radius: 50%;
}
.page-header::after {
  content: '';
  position: absolute;
  bottom: -20px; left: 20px;
  width: 100px; height: 100px;
  background: radial-gradient(circle, rgba(255,255,255,0.07) 0%, transparent 70%);
  border-radius: 50%;
}

/* Buttons */
.btn-primary {
  background: #EC623C;
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 14px 24px;
  font-family: 'Prompt', sans-serif;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  box-shadow: 0 2px 8px rgba(236,98,60,0.30);
  transition: transform 0.15s cubic-bezier(0.34,1.56,0.64,1), opacity 0.15s ease;
  position: relative; overflow: hidden;
}
.btn-primary:hover { transform: scale(1.02); box-shadow: 0 4px 16px rgba(236,98,60,0.40); }
.btn-primary:active { transform: scale(0.97); transition-duration: 0.08s; }
.btn-primary:focus-visible { outline: 3px solid #EC623C; outline-offset: 3px; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: #FEF0EB;
  color: #EC623C;
  border: 1.5px solid #FDDDD5;
  border-radius: 12px;
  padding: 13px 24px;
  font-family: 'Prompt', sans-serif;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: transform 0.15s cubic-bezier(0.34,1.56,0.64,1), background 0.15s ease;
}
.btn-secondary:hover { background: #FDDDD5; transform: scale(1.01); }
.btn-secondary:focus-visible { outline: 3px solid #EC623C; outline-offset: 3px; }
.btn-secondary:active { transform: scale(0.97); }

.btn-ghost {
  background: transparent;
  color: #EC623C;
  border: none;
  padding: 8px 12px;
  font-family: 'Prompt', sans-serif;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s ease;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-ghost:hover { background: #FEF0EB; }
.btn-ghost:focus-visible { outline: 3px solid #EC623C; outline-offset: 2px; }
.btn-ghost:active { opacity: 0.7; }

/* Cards */
.card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 1px 3px rgba(236,98,60,0.07), 0 4px 16px rgba(0,0,0,0.07);
  padding: 20px;
}

/* Form inputs */
.form-input {
  width: 100%;
  border: 1.5px solid #E7E5E4;
  border-radius: 10px;
  padding: 12px 14px;
  font-family: 'Prompt', sans-serif;
  font-size: 15px;
  color: #1C1917;
  background: #fff;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-input:focus {
  border-color: #EC623C;
  box-shadow: 0 0 0 3px rgba(236,98,60,0.12);
}
.form-input::placeholder { color: #78716C; }

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: #57534E;
  margin-bottom: 6px;
}
.form-group { margin-bottom: 20px; }

/* KB Plan Radio Cards */
.kb-radio-card:has(input:checked) {
  border-color: #EC623C;
  background: #FEF0EB;
}

/* KB Chips */
.kb-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1.5px solid #E7E5E4;
  background: #fff;
  font-size: 13px;
  color: #57534E;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s cubic-bezier(0.34,1.56,0.64,1);
  margin: 4px;
  font-family: 'Prompt', sans-serif;
}
.kb-chip:hover { border-color: #EC623C; background: #FEF0EB; }
.kb-chip:focus-visible { outline: 2px solid #EC623C; outline-offset: 2px; }
.kb-chip:active { transform: scale(0.95); }
.kb-chip.selected {
  border-color: #EC623C;
  background: #EC623C;
  color: #fff;
}

/* Role badge */
.role-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
}
.role-lc { background: rgba(255,255,255,0.25); color: #fff; }
.role-mc { background: rgba(255,255,255,0.25); color: #fff; }
.role-ic { background: rgba(255,255,255,0.25); color: #fff; }
.role-badge-dark.role-lc { background: #FEF0EB; color: #C4400F; }
.role-badge-dark.role-mc { background: #E0F2FE; color: #0369A1; }
.role-badge-dark.role-ic { background: #F0FDF4; color: #15803D; }
.role-badge-dark.role-admin { background: #F5F3FF; color: #6D28D9; }

/* Submission type badge */
.type-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.type-sbia { background: #FEF0EB; color: #C4400F; }
.type-action { background: #E0F2FE; color: #0369A1; }
.type-kb { background: #F0FDF4; color: #15803D; }

/* Toast */
#toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1C1917;
  color: #fff;
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.34,1.56,0.64,1);
  z-index: 9999;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  pointer-events: none;
  max-width: 320px;
  text-align: center;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Floating lang toggle */
#float-lang-btn {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 1100;
  background: rgba(28,25,23,0.75);
  border: 1.5px solid rgba(255,255,255,0.18);
  color: #fff;
  border-radius: 20px;
  padding: 5px 13px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.05em;
  backdrop-filter: blur(6px);
  transition: background 0.15s ease, transform 0.12s cubic-bezier(0.34,1.56,0.64,1);
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
#float-lang-btn:hover { background: rgba(236,98,60,0.85); transform: scale(1.05); }
#float-lang-btn:focus-visible { outline: 2px solid #EC623C; outline-offset: 2px; }
#float-lang-btn:active { transform: scale(0.96); }
/* Hide float btn on register page (it has its own inline toggle) */
body.on-register #float-lang-btn { display: none; }

/* Demo role switcher */
#demo-switcher {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #1C1917;
  border-radius: 999px;
  padding: 6px 8px;
  display: flex;
  gap: 4px;
  z-index: 1000;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
.demo-btn {
  padding: 5px 14px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.6);
  font-family: 'Prompt', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.demo-btn.active { background: #EC623C; color: #fff; }
.demo-btn:focus-visible { outline: 2px solid #EC623C; outline-offset: 2px; }
.demo-btn:hover:not(.active) { background: rgba(255,255,255,0.1); color: #fff; }

/* Back button row */
.back-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 20px 8px;
}

/* Divider */
.divider { height: 1px; background: #F0EDEC; margin: 4px 0; }

/* OTP input grid */
.otp-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.otp-input {
  width: 100%;
  aspect-ratio: 1;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  border: 1.5px solid #E7E5E4;
  border-radius: 10px;
  background: #fff;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  font-family: 'Prompt', sans-serif;
}
.otp-input:focus { border-color: #EC623C; box-shadow: 0 0 0 3px rgba(236,98,60,0.12); }

/* Rich menu cards */
.menu-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 1px 3px rgba(236,98,60,0.07), 0 4px 16px rgba(0,0,0,0.07);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: transform 0.25s var(--ease-out-quart), box-shadow 0.25s var(--ease-out-quart), border-color 0.2s var(--ease-out-quart);
  text-decoration: none;
  color: inherit;
  border: 1.5px solid transparent;
}
.menu-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(236,98,60,0.13), 0 2px 8px rgba(0,0,0,0.08);
  border-color: #FDDDD5;
}
.menu-card:focus-visible { outline: 3px solid #EC623C; outline-offset: 2px; }
.menu-card:active { transform: scale(0.98); transition-duration: 0.1s; }
.menu-card .menu-icon { transition: transform 0.25s var(--ease-out-quart); }
.menu-card:hover .menu-icon { transform: scale(1.08); }
.menu-icon {
  width: 52px; height: 52px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

/* Submission card */
.submission-card {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(236,98,60,0.07), 0 4px 16px rgba(0,0,0,0.07);
  overflow: hidden;
  margin-bottom: 12px;
  transition: box-shadow 0.2s var(--ease-out-quart), transform 0.2s var(--ease-out-quart);
}
.submission-card:hover { box-shadow: 0 4px 20px rgba(236,98,60,0.12), 0 2px 8px rgba(0,0,0,0.08); transform: translateY(-1px); }

/* Tabs */
.tab-row {
  display: flex;
  gap: 0;
  background: #F0EDEC;
  border-radius: 10px;
  padding: 4px;
}
.tab-btn {
  flex: 1;
  padding: 8px;
  border: none;
  background: transparent;
  border-radius: 7px;
  font-family: 'Prompt', sans-serif;
  font-size: 13px;
  font-weight: 500;
  color: #78716C;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab-btn:focus-visible { outline: 2px solid #EC623C; outline-offset: -2px; }
.tab-btn.active { background: #fff; color: #EC623C; font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,0.08); }

/* Char counter */
.char-counter { font-size: 12px; color: #78716C; text-align: right; margin-top: 4px; }
.char-counter.warn { color: #EC623C; }

/* Coaching note box */
.coaching-box {
  background: linear-gradient(135deg, #FEF0EB, #FFF5F2);
  border: 1px solid #FDDDD5;
  border-left: 3px solid #EC623C;
  border-radius: 10px;
  padding: 14px;
  margin-top: 12px;
}

/* Stats card */
.stat-card {
  background: #fff;
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 1px 3px rgba(236,98,60,0.07), 0 4px 16px rgba(0,0,0,0.07);
  text-align: center;
}

/* Activity dot */
.dot-active { width: 8px; height: 8px; border-radius: 50%; background: #22C55E; display: inline-block; }
.dot-silent { width: 8px; height: 8px; border-radius: 50%; background: #D4D0CC; display: inline-block; }

/* Admin tabs */
.admin-tab {
  flex: 1;
  padding: 10px 4px;
  border: none;
  background: transparent;
  font-family: 'Prompt', sans-serif;
  font-size: 12px;
  font-weight: 500;
  color: #78716C;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.admin-tab:focus-visible { outline: 2px solid #EC623C; outline-offset: -2px; }
.admin-tab.active { color: #EC623C; border-bottom-color: #EC623C; font-weight: 600; }

/* Chart bar */
.chart-bar {
  background: linear-gradient(180deg, #F97B55, #EC623C);
  border-radius: 4px 4px 0 0;
  transition: height 0.4s cubic-bezier(0.34,1.56,0.64,1);
}

/* Member row */
.member-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px;
  cursor: pointer;
  transition: background 0.15s var(--ease-out-quart), transform 0.15s var(--ease-out-quart);
  border-bottom: 1px solid #F0EDEC;
}
.member-row:hover { transform: translateX(4px); }
.member-row:last-child { border-bottom: none; }
.member-row:hover { background: #FEF0EB; }
.member-row:focus-visible { outline: 2px solid #EC623C; outline-offset: -2px; }
.member-row:active { background: #FDDDD5; }
.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #0D9488;
  flex-shrink: 0;
}

/* Tree connector */
.tree-line { border-left: 2px dashed #FDDDD5; margin-left: 20px; padding-left: 16px; }

/* Modal overlay */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 500;
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s var(--ease-out-quart);
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal-sheet {
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 24px 20px 40px;
  width: 100%;
  max-width: 430px;
  transform: translateY(100%);
  transition: transform 0.4s var(--ease-out-expo);
}
.modal-overlay.open .modal-sheet { transform: translateY(0); }

/* Scrollable content */
.scroll-content { overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* Step indicator */
.step-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.35);
  transition: background 0.2s ease, transform 0.2s ease;
}
.step-dot.active { background: #fff; transform: scale(1.3); }

/* Success animation */
@keyframes pop-in {
  0% { transform: scale(0.5); opacity: 0; }
  70% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}
.pop-in { animation: pop-in 0.4s cubic-bezier(0.34,1.56,0.64,1) forwards; }

@keyframes fade-up {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
.fade-up { animation: fade-up 0.45s var(--ease-out-expo) forwards; }

select.form-input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23A8A29E' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

/* ===== RESPONSIVE: iOS safe area ===== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .page { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
  #demo-switcher { bottom: calc(16px + env(safe-area-inset-bottom)); }
  #toast { bottom: calc(100px + env(safe-area-inset-bottom)); }
}

/* ===== RESPONSIVE: Small phones (320px) ===== */
@media (max-width: 360px) {
  .page-header { padding: 16px 16px 24px; }
  .page-header h1 { font-size: 20px !important; }
  .card { padding: 16px; }
  .menu-card { padding: 16px; gap: 12px; }
  .menu-icon { width: 44px; height: 44px; border-radius: 12px; font-size: 20px; }
  .otp-grid { gap: 6px; }
  .otp-input { font-size: 18px; }
  .btn-primary { padding: 12px 20px; font-size: 15px; }
  .form-input { padding: 11px 12px; font-size: 14px; }
  #demo-switcher { padding: 5px 6px; }
  .demo-btn { padding: 4px 10px; font-size: 12px; }
}

/* ===== RESPONSIVE: Tablet landscape / wider views ===== */
@media (min-width: 600px) {
  #app { max-width: 430px; }
  body { background: #F0EDEC; }
  #app { border-left: 1px solid #E7E5E4; border-right: 1px solid #E7E5E4; box-shadow: 0 0 40px rgba(0,0,0,0.06); }
}

/* ===== RESPONSIVE: Very wide (tablet full) ===== */
@media (min-width: 768px) {
  #demo-switcher { bottom: 24px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
