*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100dvh; width: 100%; overflow: hidden;
  background: var(--bg-main); color: var(--text-primary);
  font-family: var(--font-sans); font-size: 1rem; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent-color); outline-offset: 2px; }

.app-shell { display: flex; flex-direction: column; height: 100dvh; width: 100%; overflow: hidden; }
#section-stage { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; padding: 1rem; }
.app-container { max-width: 1240px; margin: 0 auto; width: 100%; }

.page-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  flex-wrap: wrap; gap: 1rem; margin-bottom: 1rem; padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
}
.page-header h1 {
  margin: 0; font-family: var(--font-display);
  font-size: clamp(1.5rem, 2.4vw, 2rem); font-weight: 600;
  line-height: 1.15; letter-spacing: -0.02em;
}
.page-subtitle { margin: 0.25rem 0 0; color: var(--text-muted); font-size: 0.875rem; }
h2 { font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; margin: 0 0 0.5rem; }
h3 { font-size: 0.95rem; font-weight: 700; margin: 0 0 0.25rem; }

.app-panel { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); box-shadow: var(--shadow-subtle); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: 2.5rem; padding: 0.5rem 1rem;
  border-radius: var(--radius-sm); border: 1px solid var(--border-subtle);
  background: var(--bg-surface); color: var(--text-primary);
  font-size: 0.875rem; font-weight: 600;
  transition: transform 0.16s var(--ease-spring), background-color 0.16s ease, border-color 0.16s ease;
}
.btn:hover { border-color: var(--border-strong); background: var(--bg-elevated); }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent-color); border-color: var(--accent-color); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-contrast); }

.segmented {
  display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.25rem;
  background: var(--bg-elevated); border: 1px solid var(--border-subtle); border-radius: var(--radius-sm);
}
.segmented button, .segmented a {
  border: none; background: transparent; padding: 0.375rem 0.75rem; min-height: 2rem;
  border-radius: var(--radius-sm); font-size: 0.8125rem; font-weight: 600; color: var(--text-muted);
  transition: transform 0.15s var(--ease-spring), background-color 0.15s ease, color 0.15s ease;
}
.segmented button:active, .segmented a:active { transform: scale(0.97); }
.segmented button.is-active, .segmented a.is-active { background: var(--bg-surface); color: var(--text-primary); box-shadow: var(--shadow-subtle); }

.mono-num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.skeleton {
  background: linear-gradient(90deg, var(--bg-muted) 25%, var(--bg-elevated) 50%, var(--bg-muted) 75%);
  background-size: 200% 100%; border-radius: var(--radius-sm);
  animation: kansoShimmer 1.3s ease-in-out infinite;
}
@keyframes kansoShimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.state-box {
  padding: 2rem 1.5rem; text-align: center; border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-md); background: var(--bg-elevated);
}
.state-box p { margin: 0.25rem 0 1rem; color: var(--text-muted); font-size: 0.875rem; }
.state-box.is-error { border-color: var(--error-color); background: var(--error-soft); }

.toast-stack { position: fixed; right: 1rem; bottom: 1rem; z-index: 90; display: flex; flex-direction: column; gap: 0.5rem; pointer-events: none; }
.toast-item {
  pointer-events: auto; min-width: 240px; max-width: 340px;
  padding: 0.75rem 1rem; border-radius: var(--radius-md);
  background: var(--bg-surface); border: 1px solid var(--border-strong);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14); font-size: 0.875rem; font-weight: 600;
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  transform: translate3d(0, 12px, 0); opacity: 0;
  transition: transform 0.25s var(--ease-spring), opacity 0.22s ease;
}
.toast-item.is-visible { transform: translate3d(0, 0, 0); opacity: 1; }
.toast-item.is-success { border-color: var(--success-color); }
.toast-item.is-error { border-color: var(--error-color); }

@media (max-width: 768px) {
  #section-stage { padding: 0.75rem; }
  .btn, .segmented button { min-height: 44px; }
  .toast-stack { left: 1rem; right: 1rem; bottom: 5rem; }
  .toast-item { max-width: none; }
}
