/* ==========================================================================
   SolveCam warm study theme
   ========================================================================== */

:root {
  --font-primary: 'Outfit', 'Noto Sans JP', sans-serif;
  --font-mono: 'Fira Code', monospace;

  --bg-main: #eef6f4;
  --bg-page-top: #fbfdfb;
  --bg-card: #ffffff;
  --bg-soft: #f5faf8;
  --bg-soft-warm: #fff6e7;
  --bg-modal: #ffffff;

  --color-primary: #2f7d6b;
  --color-primary-dark: #236758;
  --color-primary-soft: #e3f3ee;
  --color-secondary: #e88b45;
  --color-secondary-soft: #fff1df;
  --color-accent: #5778c8;
  --color-danger: #bf5146;
  --color-danger-soft: #fff0ee;
  --color-text: #203531;
  --color-text-muted: #647872;
  --color-text-soft: #879893;
  --color-border: #d8e7e2;
  --color-border-strong: #c7d9d3;

  --shadow-card: 0 14px 36px rgba(36, 70, 63, 0.09);
  --shadow-soft: 0 8px 22px rgba(36, 70, 63, 0.07);
  --shadow-action: 0 10px 24px rgba(47, 125, 107, 0.25);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --transition-smooth: all 0.24s ease;
  --transition-fast: all 0.14s ease;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  min-height: 100%;
  overflow-x: hidden;
  background:
    linear-gradient(180deg, var(--bg-page-top) 0%, var(--bg-main) 42%, #e8f1ee 100%);
  color: var(--color-text);
  font-family: var(--font-primary);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100dvh;
}

.bg-blur-effect {
  display: none;
}

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 500px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 12px) + 8px) 12px calc(env(safe-area-inset-bottom, 12px) + 14px);
  position: relative;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 2px 14px;
  gap: 12px;
}

.is-result-view .app-header {
  display: none;
}

.is-result-view .app-container {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  padding-top: max(env(safe-area-inset-top, 0px), 8px);
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 8px);
}

.is-result-view .app-main {
  flex: 1;
  min-height: 0;
}

.is-result-view #result-section.app-card {
  flex: 1;
  height: auto;
  min-height: 0;
  margin-bottom: 0;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.logo-icon {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: var(--color-primary);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 18px rgba(47, 125, 107, 0.22);
}

.logo-icon i {
  font-size: 19px;
}

.logo-text {
  min-width: 0;
}

.logo-text h1 {
  font-size: 22px;
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: 0;
  color: var(--color-text);
}

.logo-tag {
  display: block;
  margin-top: 4px;
  font-size: 11.5px;
  line-height: 1.2;
  color: var(--color-text-muted);
  font-weight: 700;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}

.app-version {
  flex: 0 0 auto;
  margin-left: 2px;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--color-secondary-soft);
  border: 1px solid #f0d4ad;
  color: #92621f;
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.2;
}

.app-main {
  display: flex;
  flex-direction: column;
}

.app-card {
  display: none;
  flex-direction: column;
  gap: 18px;
  margin-bottom: 16px;
  padding: 18px;
  background: var(--bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  transition: var(--transition-smooth);
}

.app-card.active {
  display: flex;
  animation: fadeInUp 0.28s ease-out;
}

#result-section.app-card {
  min-height: calc(100dvh - 78px);
  padding: 14px 14px 0;
  gap: 0;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card-hero {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  gap: 13px;
  padding: 8px 2px 2px;
}

.hero-icon {
  width: 74px;
  height: 74px;
  border-radius: 22px;
  background: var(--color-primary-soft);
  border: 1px solid #cce4dc;
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 31px;
  margin-bottom: 2px;
}

.card-hero h2 {
  font-size: 24px;
  line-height: 1.28;
  font-weight: 800;
  color: var(--color-text);
  letter-spacing: 0;
}

.card-hero p {
  font-size: 15px;
  line-height: 1.85;
  color: var(--color-text-muted);
  max-width: 390px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 12px;
}

.card-header h3 {
  min-width: 0;
  font-size: 16px;
  line-height: 1.35;
  font-weight: 800;
  color: var(--color-text);
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 54px;
  padding: 14px 18px;
  border-radius: 15px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.25;
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition-fast);
}

.btn-primary,
.btn-glow {
  background: var(--color-primary);
  color: #ffffff;
  box-shadow: var(--shadow-action);
}

.btn-primary:active,
.btn-glow:active {
  transform: translateY(1px) scale(0.99);
  background: var(--color-primary-dark);
  box-shadow: 0 5px 14px rgba(47, 125, 107, 0.2);
}

.btn-glow {
  position: relative;
  overflow: hidden;
}

.btn-glow::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.16), transparent);
  transform: translateX(-100%);
  transition: transform 0.5s ease;
}

.btn-glow:active::after {
  transform: translateX(100%);
}

.btn-secondary {
  background: var(--bg-soft);
  border-color: var(--color-border);
  color: #284a44;
  box-shadow: none;
}

.btn-secondary:active {
  background: #ebf4f1;
  transform: translateY(1px);
}

.icon-btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--color-border);
  background: #ffffff;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: var(--transition-fast);
}

.icon-btn:active {
  transform: scale(0.96);
  color: var(--color-primary);
  border-color: var(--color-primary);
}

.text-btn {
  flex: 0 0 auto;
  background: transparent;
  border: none;
  color: var(--color-primary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.3;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.text-btn-danger {
  background: transparent;
  border: none;
  color: var(--color-danger);
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.text-btn:active,
.text-btn-danger:active {
  opacity: 0.72;
}

.upload-controls {
  display: flex;
  flex-direction: column;
  gap: 11px;
  width: 100%;
}

.image-preview-wrapper {
  width: 100%;
  height: min(60dvh, 460px);
  min-height: 280px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--color-border-strong);
  background:
    linear-gradient(45deg, #edf3f1 25%, transparent 25%),
    linear-gradient(-45deg, #edf3f1 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #edf3f1 75%),
    linear-gradient(-45deg, transparent 75%, #edf3f1 75%);
  background-color: #ffffff;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  touch-action: none;
  user-select: none;
}

.image-preview-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.selection-box {
  position: absolute;
  display: none;
  border: 2px solid var(--color-secondary);
  background: rgba(232, 139, 69, 0.18);
  box-shadow:
    0 0 0 9999px rgba(32, 53, 49, 0.34),
    0 0 0 4px rgba(255, 255, 255, 0.78);
  border-radius: 8px;
  pointer-events: none;
}

.selection-box.active {
  display: block;
}

.selection-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
  padding: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.selection-hint {
  font-size: 13px;
  line-height: 1.75;
  color: var(--color-text-muted);
}

.analysis-instruction-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  padding: 13px 14px;
  background: #fffaf2;
  border: 1px solid #ecd7b8;
  border-radius: var(--radius-md);
}

.analysis-instruction-group label {
  font-size: 13.5px;
  line-height: 1.4;
  font-weight: 800;
  color: var(--color-text);
}

.analysis-instruction-group label span {
  margin-left: 5px;
  font-size: 11px;
  font-weight: 700;
  color: var(--color-text-muted);
}

#analysis-instruction-input {
  width: 100%;
  min-height: 82px;
  resize: vertical;
  padding: 11px 12px;
  border: 1px solid var(--color-border-strong);
  border-radius: 12px;
  background: #ffffff;
  color: var(--color-text);
  font-family: inherit;
  font-size: 16px;
  line-height: 1.65;
  transition: var(--transition-fast);
}

#analysis-instruction-input::placeholder {
  color: #87948f;
}

#analysis-instruction-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(47, 125, 107, 0.16);
}

.analysis-instruction-group p {
  margin: 0;
  font-size: 12px;
  line-height: 1.65;
  color: var(--color-text-muted);
}

.analysis-controls {
  width: 100%;
}

.loading-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 18px;
  padding: 48px 10px;
}

.loading-spinner {
  width: 52px;
  height: 52px;
  position: relative;
}

.double-bounce1,
.double-bounce2 {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background-color: var(--color-primary);
  opacity: 0.52;
  position: absolute;
  top: 0;
  left: 0;
  animation: sk-bounce 2s infinite ease-in-out;
}

.double-bounce2 {
  background-color: var(--color-secondary);
  animation-delay: -1s;
}

@keyframes sk-bounce {
  0%, 100% {
    transform: scale(0);
  }
  50% {
    transform: scale(1);
  }
}

.loading-wrapper h3 {
  font-size: 18px;
  line-height: 1.45;
  font-weight: 800;
}

.loading-wrapper p {
  font-size: 14px;
  line-height: 1.8;
  color: var(--color-text-muted);
  max-width: 330px;
}

.result-scroll-container {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 0 16px;
  padding-right: 2px;
  -webkit-overflow-scrolling: touch;
}

.result-scroll-container::-webkit-scrollbar {
  width: 6px;
}

.result-scroll-container::-webkit-scrollbar-track {
  background: transparent;
}

.result-scroll-container::-webkit-scrollbar-thumb {
  background: #b8cbc5;
  border-radius: 999px;
}

.active-model-tag {
  max-width: 48%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
  line-height: 1.25;
  background: var(--color-primary-soft);
  color: var(--color-primary-dark);
  padding: 5px 8px;
  border-radius: 999px;
  border: 1px solid #cce4dc;
  font-family: var(--font-mono);
}

.preview-mini-container details {
  background: var(--bg-soft);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  transition: var(--transition-fast);
}

.preview-mini-container summary {
  font-size: 13px;
  line-height: 1.45;
  cursor: pointer;
  color: var(--color-text-muted);
  user-select: none;
  font-weight: 800;
}

.preview-mini-container details[open] summary {
  margin-bottom: 10px;
  color: var(--color-text);
}

#image-preview-mini {
  width: 100%;
  max-height: 150px;
  object-fit: contain;
  border-radius: 12px;
  background: #ffffff;
  border: 1px solid var(--color-border);
}

.explanation-container {
  width: 100%;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
}

.markdown-body {
  font-size: 15px;
  line-height: 1.85;
  color: var(--color-text);
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  color: var(--color-text);
  font-weight: 800;
  letter-spacing: 0;
}

.markdown-body h1 {
  margin: 22px 0 12px;
  padding-bottom: 8px;
  font-size: 20px;
  line-height: 1.4;
  border-bottom: 2px solid var(--color-primary-soft);
}

.markdown-body h2 {
  margin: 20px 0 10px;
  padding: 8px 10px;
  font-size: 17px;
  line-height: 1.45;
  border-left: 4px solid var(--color-primary);
  background: var(--bg-soft);
  border-radius: 0 10px 10px 0;
}

.markdown-body h3 {
  margin: 18px 0 8px;
  font-size: 16px;
  line-height: 1.45;
}

.markdown-body p {
  margin-bottom: 14px;
}

.markdown-body ul,
.markdown-body ol {
  margin-bottom: 14px;
  padding-left: 22px;
}

.markdown-body li {
  margin-bottom: 7px;
}

.structured-result {
  display: flex;
  flex-direction: column;
  gap: 0;
  font-size: 15px;
  line-height: 1.75;
}

.structured-title {
  margin: 2px 0 6px;
  padding: 0;
  font-size: 21px;
  line-height: 1.4;
  color: var(--color-text);
  border: none;
}

.structured-meta {
  align-self: flex-start;
  margin-bottom: 10px;
  font-size: 10.5px;
  line-height: 1.25;
  font-family: var(--font-mono);
  color: var(--color-primary-dark);
  background: var(--color-primary-soft);
  border: 1px solid #cce4dc;
  border-radius: 999px;
  padding: 4px 8px;
}

.structured-summary {
  border: 0;
  border-top: 1px solid var(--color-border);
  background: transparent;
}

.structured-summary:last-of-type {
  border-bottom: 1px solid var(--color-border);
}

.structured-summary-heading {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 48px;
  cursor: pointer;
  list-style: none;
  color: var(--color-text);
  font-size: 15.5px;
  font-weight: 800;
}

.structured-summary-heading::-webkit-details-marker {
  display: none;
}

.structured-summary-heading::after {
  content: '';
  width: 8px;
  height: 8px;
  margin-left: auto;
  border-right: 2px solid var(--color-text-muted);
  border-bottom: 2px solid var(--color-text-muted);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform 0.18s ease;
}

.structured-summary:not([open]) .structured-summary-heading::after {
  transform: rotate(-45deg) translate(-1px, -1px);
}

.structured-summary-content {
  padding: 0 4px 12px 43px;
}

.structured-summary-content p {
  margin: 0;
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.75;
}

.structured-summary--answer {
  border-top-color: #f0d4ad;
}

.structured-summary--answer .structured-section-icon {
  color: #ffffff;
  background: var(--color-secondary);
  border-color: var(--color-secondary);
}

.structured-summary--answer .structured-summary-title,
.structured-summary--answer .structured-summary-content {
  color: #c7621d;
}

.structured-nav {
  position: sticky;
  top: -14px;
  z-index: 5;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  margin: 10px 0 2px;
  padding: 4px;
  background: #ffffff;
  border: 1px solid var(--color-border);
  border-radius: 9px;
  box-shadow: 0 5px 14px rgba(36, 70, 63, 0.07);
}

.structured-nav-button {
  position: relative;
  min-height: 38px;
  padding: 7px 5px 9px;
  border: 0;
  background: transparent;
  color: var(--color-text-muted);
  font: 800 12.5px/1.2 var(--font-primary);
  cursor: pointer;
}

.structured-nav-button::after {
  content: '';
  position: absolute;
  right: 10px;
  bottom: 1px;
  left: 10px;
  height: 2px;
  border-radius: 999px;
  background: transparent;
}

.structured-nav-button.is-active {
  color: var(--color-primary-dark);
}

.structured-nav-button.is-active::after {
  background: var(--color-primary);
}

.structured-section,
.structured-step {
  display: flex;
  flex-direction: column;
  gap: 9px;
  background: transparent;
}

.structured-section {
  padding: 16px 3px;
  border: 0;
  border-bottom: 1px solid var(--color-border);
  border-radius: 0;
  box-shadow: none;
  scroll-margin-top: 68px;
}

.structured-error {
  background: #fff7f3;
  border-color: #e8b7a5;
  border-left: 4px solid #bf5146;
}

.structured-error h2 {
  color: #9f3f37;
}

.structured-section-heading {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.structured-section-icon {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid #cce4dc;
  border-radius: 8px;
  background: var(--color-primary-soft);
  color: var(--color-primary);
  font-size: 15px;
}

.structured-section h2,
.structured-step h3 {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  font-size: 16px;
  line-height: 1.4;
  color: var(--color-text);
}

.structured-section-rule {
  flex: 0 0 24px;
  height: 1px;
  margin-left: 3px;
  background: var(--color-primary);
}

.structured-section p,
.structured-step p {
  white-space: pre-wrap;
  margin: 0;
  font-size: 15px;
  line-height: 1.75;
  color: var(--color-text);
}

.structured-list {
  margin: 0;
  padding-left: 22px;
}

.structured-list li {
  margin: 0 0 7px;
  padding-left: 2px;
  font-size: 14.5px;
  line-height: 1.7;
}

.structured-list li:last-child {
  margin-bottom: 0;
}

.structured-section--knowledge .structured-list {
  list-style: none;
  padding-left: 0;
}

.structured-section--knowledge .structured-list li {
  position: relative;
  padding-left: 29px;
}

.structured-section--knowledge .structured-list li::before {
  content: '✓';
  position: absolute;
  top: 0.05em;
  left: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #ffffff;
  font-size: 11px;
  font-weight: 900;
}

.structured-coaching-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.structured-coaching-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 11px;
  background: #ffffff;
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.structured-coaching-card-heading {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.structured-coaching-card h3 {
  flex: 1;
  margin: 0;
  font-size: 14.5px;
  line-height: 1.45;
  color: var(--color-primary-dark);
}

.structured-coaching-row {
  display: grid;
  grid-template-columns: minmax(62px, auto) minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  font-size: 14px;
  line-height: 1.65;
}

.structured-coaching-label {
  font-weight: 800;
  color: var(--color-text-muted);
}

.structured-coaching-value {
  min-width: 0;
  color: var(--color-text);
  white-space: pre-wrap;
}

.structured-coaching-card--clue {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  align-items: start;
  gap: 10px;
  padding: 10px 0;
  border: 0;
  border-bottom: 1px solid var(--color-border);
  border-radius: 0;
}

.structured-coaching-card--clue:last-child {
  border-bottom: 0;
}

.structured-coaching-card--clue .structured-coaching-card-heading::after {
  content: '→';
  margin-left: auto;
  color: var(--color-primary);
  font-weight: 900;
}

.structured-coaching-card--clue .structured-coaching-row {
  grid-template-columns: 1fr;
  gap: 2px;
}

.structured-coaching-card--clue .structured-coaching-label {
  font-size: 11.5px;
  color: var(--color-primary);
}

.structured-coaching-card--strategy.is-selected,
.structured-coaching-card--decision {
  border-color: var(--color-primary);
  background: #f8fcfb;
  box-shadow: inset 3px 0 0 var(--color-primary);
}

.structured-selected-marker,
.structured-plan-index,
.structured-step-index {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
}

.structured-section--plan .structured-coaching-list,
.structured-steps-list {
  position: relative;
  display: flex;
  flex-direction: column;
}

.structured-section--plan .structured-coaching-list::before,
.structured-steps-list::before {
  content: '';
  position: absolute;
  top: 13px;
  bottom: 15px;
  left: 12px;
  width: 2px;
  background: #b7dacf;
}

.structured-coaching-card--plan {
  position: relative;
  gap: 3px;
  padding: 0 0 12px 42px;
  border: 0;
  background: transparent;
}

.structured-coaching-card--plan:last-child {
  padding-bottom: 0;
}

.structured-coaching-card--plan .structured-plan-index {
  position: absolute;
  top: 0;
  left: -42px;
}

.structured-coaching-card--plan .structured-coaching-row {
  grid-template-columns: 1fr;
  gap: 1px;
}

.structured-coaching-card--plan .structured-coaching-label {
  font-size: 11.5px;
  color: var(--color-primary);
}

.structured-steps-list {
  gap: 0;
}

.structured-step {
  position: relative;
  gap: 7px;
  padding: 0 0 18px 43px;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.structured-step:last-child {
  padding-bottom: 0;
}

.structured-step-heading {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 25px;
}

.structured-step-index {
  position: absolute;
  top: 0;
  left: -43px;
}

.structured-section--retention {
  margin-top: 6px;
  padding: 14px;
  border: 1px solid #b9ddd3;
  border-radius: 11px;
  background: #edf8f4;
}

.structured-section--retention .structured-coaching-card {
  padding: 6px 0;
  border: 0;
  background: transparent;
}

.structured-section--self-check .structured-list {
  list-style: none;
  padding-left: 0;
}

.structured-section--self-check .structured-list li {
  position: relative;
  padding-left: 27px;
}

.structured-section--self-check .structured-list li::before {
  content: '';
  position: absolute;
  top: 0.35em;
  left: 1px;
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--color-primary);
  border-radius: 3px;
}

.structured-equations {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.structured-equation {
  position: relative;
  width: 100%;
  overflow-x: hidden;
  overflow-y: visible;
  background: #fffaf4;
  border: 0;
  border-left: 2px solid #e6ad72;
  border-radius: 3px;
  padding: 5px 10px;
  line-height: 1.45;
  scrollbar-width: thin;
  scrollbar-color: #d4995d #fff2dd;
}

.structured-equation::-webkit-scrollbar,
.katex-display::-webkit-scrollbar,
.markdown-body pre::-webkit-scrollbar,
.graph-diagram::-webkit-scrollbar {
  height: 6px;
}

.structured-equation:not(.is-scrollable-x) {
  scrollbar-width: none;
}

.structured-equation:not(.is-scrollable-x)::-webkit-scrollbar {
  display: none;
}

.structured-equation .katex-display {
  margin: 0;
  padding: 0;
}

.structured-equation::-webkit-scrollbar-track,
.katex-display::-webkit-scrollbar-track,
.markdown-body pre::-webkit-scrollbar-track,
.graph-diagram::-webkit-scrollbar-track {
  background: #f3e5d2;
  border-radius: 999px;
}

.structured-equation::-webkit-scrollbar-thumb,
.katex-display::-webkit-scrollbar-thumb,
.markdown-body pre::-webkit-scrollbar-thumb,
.graph-diagram::-webkit-scrollbar-thumb {
  background: #d4995d;
  border-radius: 999px;
}

.structured-equation.is-scrollable-x,
.katex-display.is-scrollable-x,
.markdown-body pre.is-scrollable-x,
.graph-diagram.is-scrollable-x {
  position: relative;
  padding-right: 20px;
  border-right-color: var(--color-secondary);
  box-shadow:
    inset -1px 0 0 rgba(232, 139, 69, 0.9),
    inset -18px 0 18px -15px rgba(232, 139, 69, 0.75);
}

.structured-equation.is-scrollable-x {
  overflow-x: auto;
}

.structured-equation.equation-fallback {
  font-family: var(--font-mono);
  font-size: 13px;
  color: #7f4c18;
  white-space: pre-wrap;
}

.structured-inline-equation {
  display: inline-block;
  max-width: 100%;
  overflow: visible;
  line-height: 1.45;
  vertical-align: -0.15em;
}

.structured-inline-equation.equation-fallback {
  font-family: var(--font-mono);
  font-size: 0.92em;
  color: #7f4c18;
}

.graph-diagram {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  margin: 12px 0;
  padding: 10px;
  background: #ffffff;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  scrollbar-width: thin;
  scrollbar-color: #d4995d #fff2dd;
}

.structured-equation .katex-display > .katex {
  font-size: calc(1.21em * var(--equation-scale, 1));
}

.structured-equation.is-equation-fitted {
  overflow-x: hidden;
}

.structured-equation.is-equation-fitted .katex-display {
  overflow-x: hidden;
  scrollbar-width: none;
}

.structured-equation.is-equation-fitted .katex-display::-webkit-scrollbar {
  display: none;
}

.graph-diagram-title {
  margin: 0 0 8px;
  font-size: 13px;
  line-height: 1.45;
  font-weight: 800;
  color: var(--color-text);
}

.graph-diagram-svg {
  display: block;
  width: 100%;
  min-width: 340px;
  height: auto;
  color: var(--color-text);
}

.graph-bg {
  fill: #fbfdfb;
}

.graph-plot-bg {
  fill: #ffffff;
  stroke: #d8e7e2;
  stroke-width: 1;
}

.graph-grid {
  stroke: #d8e7e2;
  stroke-width: 1;
}

.graph-axis {
  stroke: #203531;
  stroke-width: 1.7;
}

.graph-curve {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.graph-segment {
  stroke-width: 2.4;
  stroke-linecap: round;
}

.graph-area {
  stroke: none;
}

.graph-point {
  stroke: #ffffff;
  stroke-width: 2;
}

.graph-label,
.graph-axis-label,
.graph-tick-label,
.graph-annotation {
  font-family: var(--font-primary);
  letter-spacing: 0;
}

.graph-label {
  font-size: 15px;
  font-weight: 800;
  paint-order: stroke;
  stroke: #ffffff;
  stroke-width: 4px;
  stroke-linejoin: round;
}

.graph-axis-label {
  fill: var(--color-text);
  font-size: 15px;
  font-weight: 800;
}

.graph-tick-label {
  fill: var(--color-text-muted);
  font-size: 12px;
}

.graph-annotation {
  fill: var(--color-text);
  font-size: 14px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #ffffff;
  stroke-width: 4px;
  stroke-linejoin: round;
}

.graph-diagram-notes {
  margin: 9px 0 0 18px;
  color: var(--color-text-muted);
  font-size: 13px;
  line-height: 1.65;
}

.markdown-body blockquote {
  background: var(--color-primary-soft);
  border-left: 4px solid var(--color-primary);
  padding: 13px 15px;
  border-radius: 0 12px 12px 0;
  margin-bottom: 16px;
  font-size: 14px;
  line-height: 1.8;
  color: #315a52;
}

.markdown-body code {
  font-family: var(--font-mono);
  background: #edf5f2;
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.92em;
  color: #9a4f1f;
}

.markdown-body pre {
  background: #273b36;
  color: #f2fbf8;
  padding: 13px;
  border-radius: 12px;
  overflow-x: auto;
  margin-bottom: 16px;
  border: 1px solid #334e47;
  scrollbar-width: thin;
  scrollbar-color: #d4995d rgba(255, 255, 255, 0.15);
}

.markdown-body pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}

.katex-display {
  overflow-x: auto;
  overflow-y: visible;
  padding: 10px 2px;
  line-height: 1.5;
  margin: 0.55em 0;
  scrollbar-width: thin;
  scrollbar-color: #d4995d #fff2dd;
}

.katex {
  line-height: 1.35;
}

.katex .frac-line {
  border-bottom-width: 0.05em;
  min-height: 1px;
}

.chat-bubble .katex,
.markdown-body .katex,
.structured-result .katex {
  overflow: visible;
}

.katex .katex-mathml {
  position: absolute;
  clip: rect(1px, 1px, 1px, 1px);
  padding: 0;
  border: 0;
  height: 1px;
  width: 1px;
  overflow: hidden;
}

.history-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 0 4px;
}

.section-title h3 {
  font-size: 15px;
  line-height: 1.45;
  font-weight: 800;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-empty {
  text-align: center;
  padding: 26px 18px;
  border: 1px dashed var(--color-border-strong);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.62);
  font-size: 13.5px;
  line-height: 1.8;
  color: var(--color-text-muted);
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #ffffff;
  border: 1px solid var(--color-border);
  border-radius: 16px;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: var(--transition-fast);
}

.history-item:active {
  background: var(--bg-soft);
  transform: translateY(1px);
}

.history-thumb {
  flex: 0 0 auto;
  width: 50px;
  height: 50px;
  border-radius: 12px;
  background: var(--bg-soft);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
}

.history-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.history-info {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.history-name {
  font-size: 14px;
  line-height: 1.35;
  font-weight: 800;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-date {
  font-size: 12px;
  line-height: 1.35;
  color: var(--color-text-soft);
}

.history-delete-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: transparent;
  border: none;
  color: var(--color-text-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-fast);
}

.history-delete-btn:active {
  color: var(--color-danger);
  background: var(--color-danger-soft);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(39, 59, 54, 0.34);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: var(--bg-modal);
  border: 1px solid var(--color-border);
  width: 100%;
  max-width: 420px;
  max-height: calc(100dvh - 32px);
  border-radius: 22px;
  box-shadow: 0 24px 60px rgba(32, 53, 49, 0.23);
  animation: modalScaleUp 0.22s ease-out;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

@keyframes modalScaleUp {
  from {
    opacity: 0;
    transform: scale(0.97);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--color-border);
}

.modal-header h2 {
  font-size: 18px;
  line-height: 1.35;
  font-weight: 800;
  color: var(--color-text);
  display: flex;
  align-items: center;
  gap: 10px;
}

.close-btn {
  flex: 0 0 auto;
  background: #f1f7f5;
  border: 1px solid var(--color-border);
  width: 36px;
  height: 36px;
  border-radius: 12px;
  font-size: 24px;
  color: var(--color-text-muted);
  cursor: pointer;
  line-height: 1;
}

.close-btn:active {
  color: var(--color-text);
  background: #e7f1ee;
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.form-group label {
  font-size: 13.5px;
  line-height: 1.35;
  font-weight: 800;
  color: var(--color-text);
}

.form-group input,
.form-group select {
  width: 100%;
  min-height: 46px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  font-size: 16px;
  font-family: inherit;
  transition: var(--transition-fast);
}

.form-group select {
  color: var(--color-text);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--color-primary);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(47, 125, 107, 0.16);
}

.help-text {
  font-size: 12px;
  line-height: 1.7;
  color: var(--color-text-muted);
}

.link-text {
  font-size: 13px;
  line-height: 1.45;
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.link-text:active {
  opacity: 0.8;
}

.modal-footer {
  padding: 16px 20px 20px;
  border-top: 1px solid var(--color-border);
  background: #ffffff;
}

.chat-thread-container {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-top: 20px;
  border-top: 1px dashed var(--color-border-strong);
  padding-top: 20px;
}

.chat-bubble-wrapper {
  display: flex;
  flex-direction: column;
  width: 100%;
  animation: bubbleFadeIn 0.28s ease-out;
}

@keyframes bubbleFadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.bubble-label {
  font-size: 11px;
  line-height: 1.35;
  font-weight: 800;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.bubble-label.user {
  color: #9a5a25;
  align-self: flex-end;
  margin-right: 8px;
}

.bubble-label.ai {
  color: var(--color-primary-dark);
  align-self: flex-start;
  margin-left: 8px;
}

.chat-bubble {
  max-width: 90%;
  padding: 13px 15px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.75;
}

.chat-bubble .chat-paragraph {
  margin: 0 0 11px;
  white-space: pre-wrap;
}

.chat-bubble .chat-paragraph:last-child {
  margin-bottom: 0;
}

.chat-table-wrapper {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  margin: 4px 0 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: #ffffff;
}

.chat-table {
  width: 100%;
  min-width: 420px;
  border-collapse: collapse;
  font-size: 13.5px;
  line-height: 1.6;
}

.chat-table th,
.chat-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
  vertical-align: top;
  text-align: left;
}

.chat-table th:last-child,
.chat-table td:last-child {
  border-right: 0;
}

.chat-table tr:last-child td {
  border-bottom: 0;
}

.chat-table th {
  background: var(--bg-soft);
  color: var(--color-primary-dark);
  font-weight: 800;
}

.chat-bubble.user {
  align-self: flex-end;
  background: var(--color-secondary);
  color: #ffffff;
  border-top-right-radius: 6px;
  box-shadow: 0 8px 18px rgba(232, 139, 69, 0.22);
}

.chat-bubble.ai {
  align-self: flex-start;
  width: 100%;
  max-width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-top-left-radius: 6px;
}

.chat-heading {
  margin: 14px 0 7px;
  color: var(--color-primary-dark);
  font-size: 15px;
  line-height: 1.45;
}

.chat-heading:first-child {
  margin-top: 0;
}

.chat-quote {
  margin: 5px 0 12px;
  padding: 10px 12px;
  border-left: 4px solid var(--color-primary);
  border-radius: 0 10px 10px 0;
  background: #ffffff;
  color: #315a52;
  white-space: pre-wrap;
}

.chat-divider {
  height: 0;
  margin: 15px 0;
  border: 0;
  border-top: 1px dashed var(--color-border-strong);
}

.follow-up-input-area {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 8px 2px 6px;
  border-top: 1px solid var(--color-border);
  position: relative;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 0 0 18px 18px;
}

.follow-up-template-wrap {
  position: relative;
  min-width: 0;
}

.follow-up-template-wrap::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 28px;
  height: 100%;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.92));
}

.follow-up-template-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 0 30px 2px 1px;
  scrollbar-width: none;
}

.follow-up-template-row::-webkit-scrollbar {
  display: none;
}

.follow-up-chip {
  flex: 0 0 auto;
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid var(--color-border-strong);
  border-radius: 15px;
  background: #ffffff;
  color: var(--color-text);
  font-size: 12px;
  font-weight: 800;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: var(--transition-fast);
}

.follow-up-chip i {
  color: var(--color-primary);
  font-size: 12px;
}

.follow-up-chip:active {
  transform: scale(0.96);
  border-color: var(--color-primary);
  background: var(--bg-soft);
}

.follow-up-composer {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  position: relative;
}

#follow-up-input {
  flex: 1;
  background: var(--bg-soft);
  border: 1px solid var(--color-border-strong);
  border-radius: 14px;
  color: var(--color-text);
  padding: 9px 12px;
  font-size: 16px;
  font-family: inherit;
  resize: none;
  min-height: 48px;
  max-height: 190px;
  overflow-y: auto;
  outline: none;
  transition: var(--transition-fast);
  line-height: 1.45;
}

#follow-up-input::placeholder {
  color: #8da09b;
}

#follow-up-input:focus {
  border-color: var(--color-primary);
  background: #ffffff;
  min-height: 88px;
  box-shadow: 0 0 0 3px rgba(47, 125, 107, 0.15);
}

.send-btn {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--color-primary);
  border: none;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-action);
  transition: var(--transition-fast);
}

.send-btn i {
  font-size: 17px;
  margin-left: -2px;
}

.send-btn:active {
  transform: scale(0.94);
  background: var(--color-primary-dark);
}

.follow-up-spinner {
  position: absolute;
  right: 10px;
  bottom: 11px;
  font-size: 22px;
  color: var(--color-primary);
}

.structured-nav-button:focus-visible,
.structured-summary-heading:focus-visible {
  outline: 3px solid rgba(47, 125, 107, 0.25);
  outline-offset: 2px;
}

@media (max-width: 430px) {
  .app-container {
    padding-left: 10px;
    padding-right: 10px;
  }

  .logo-icon {
    width: 38px;
    height: 38px;
    border-radius: 12px;
  }

  .logo-text h1 {
    font-size: 20px;
  }

  .logo-tag {
    font-size: 10.5px;
    max-width: 210px;
  }

  .app-card {
    padding: 16px;
    border-radius: 18px;
  }

  #result-section.app-card {
    padding: 12px 12px 0;
  }

  .card-hero h2 {
    font-size: 22px;
  }

  .card-hero p {
    font-size: 14.5px;
  }

  .card-header h3 {
    font-size: 15px;
  }

  .text-btn {
    font-size: 13px;
  }

  .active-model-tag {
    max-width: 44%;
  }

  .structured-title {
    font-size: 19px;
  }

  .structured-summary-content {
    padding-left: 41px;
  }

  .structured-section {
    padding: 14px 2px;
  }

  .structured-section--retention {
    padding: 12px;
  }

  .structured-section h2,
  .structured-step h3 {
    font-size: 15.5px;
  }

  .structured-section p,
  .structured-step p,
  .markdown-body {
    font-size: 14.5px;
  }

  .structured-coaching-row {
    grid-template-columns: minmax(68px, auto) minmax(0, 1fr);
    gap: 7px;
  }

  .structured-equation {
    padding: 5px 8px;
  }

  .structured-equation.is-scrollable-x {
    padding-right: 18px;
  }

  .structured-equation .katex-display {
    margin: 0;
  }

  .graph-diagram {
    overflow-x: hidden;
  }

  .graph-diagram-svg {
    min-width: 0;
  }

  .modal-overlay {
    padding: 12px;
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding-left: 16px;
    padding-right: 16px;
  }
}

@media (max-width: 350px) {
  .structured-nav-button {
    padding-right: 3px;
    padding-left: 3px;
    font-size: 11.5px;
  }

  .structured-coaching-card--clue {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .structured-coaching-card--clue .structured-coaching-card-heading::after {
    content: '↓';
  }

  .structured-coaching-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .structured-summary-heading::after,
  .structured-nav-button {
    transition: none;
  }
}

@media print {
  @page {
    size: A4;
    margin: 10mm;
  }

  html,
  body {
    overflow: visible;
    background: #ffffff;
  }

  .app-container {
    max-width: none;
    min-height: 0;
    padding: 0;
  }

  .app-card,
  .chat-bubble {
    box-shadow: none;
  }

  .structured-section,
  .structured-step,
  .structured-equation,
  .chat-bubble-wrapper,
  .graph-diagram {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .structured-equation,
  .graph-diagram,
  .chat-table-wrapper {
    overflow: visible;
  }

  .follow-up-input-area,
  .structured-nav,
  #open-settings-btn {
    display: none !important;
  }
}
