/*
 * Mini-app kit: the shared look for Snapnote mini-apps.
 * Copied into every package as kit/kit.css, so packages never load styles
 * from the network. Apps set --accent in their own stylesheet.
 *
 * Text follows the reader's Dynamic Type size inside Snapnote through
 * `-apple-system-body`; every size below is in rem so it scales with it.
 */

:root {
  color-scheme: light dark;
  --accent: #2d7ff9;
  --on-accent: #ffffff;
  --canvas: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #f7f7fa;
  --ink: #111114;
  --muted: #5f5f66;
  --line: rgba(60, 60, 67, 0.18);
  --control-line: rgba(60, 60, 67, 0.36);
  --danger: #c62828;
  --success: #1b7f3b;
  --radius: 12px;
  --radius-small: 8px;
  --gutter: 16px;
  --mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --ink: #f5f5f7;
    --muted: #a1a1a8;
    --line: rgba(84, 84, 88, 0.6);
    --control-line: rgba(235, 235, 245, 0.3);
    --danger: #ff6b6b;
    --success: #4cd17a;
  }
}

* {
  box-sizing: border-box;
}

html {
  font-size: 17px;
  font: -apple-system-body;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, system-ui, 'Apple SD Gothic Neo', 'Noto Sans KR', 'Segoe UI', sans-serif;
  line-height: 1.4;
  overscroll-behavior-y: none;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

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

.mk-app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 calc(var(--gutter) + env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom)) calc(var(--gutter) + env(safe-area-inset-left));
}

/* The header shows on the web. Inside Snapnote the navigation bar shows the title instead. */
.mk-header {
  padding: calc(20px + env(safe-area-inset-top)) 0 8px;
}
.mk-header h1 {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.mk-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}
html[data-host='snapnote'] .mk-header {
  display: none;
}
html[data-host='snapnote'] .mk-app {
  padding-top: 12px;
}

.mk-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Segmented control */
.mk-segments {
  display: flex;
  gap: 2px;
  padding: 2px;
  margin: 12px 0;
  background: var(--surface-2);
  border-radius: 10px;
  overflow-x: auto;
  scrollbar-width: none;
}
.mk-segments::-webkit-scrollbar {
  display: none;
}
.mk-segments button {
  flex: 1 0 auto;
  min-height: 36px;
  padding: 6px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.mk-segments button[aria-selected='true'] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* Chips: a horizontally scrolling filter row */
.mk-chips {
  display: flex;
  gap: 8px;
  margin: 12px calc(-1 * var(--gutter));
  padding: 2px var(--gutter);
  overflow-x: auto;
  scrollbar-width: none;
}
.mk-chips::-webkit-scrollbar {
  display: none;
}
.mk-chip {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.88rem;
  font-weight: 500;
}
.mk-chip[aria-pressed='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

/* Grouped sections */
.mk-section {
  margin: 20px 0;
}
.mk-section > h2 {
  margin: 0 0 6px 4px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}
.mk-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.mk-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}
.mk-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 10px 16px;
  position: relative;
}
.mk-row + .mk-row::before {
  content: '';
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  border-top: 0.5px solid var(--line);
}
button.mk-row {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: start;
}
button.mk-row:active {
  background: var(--surface-2);
}
.mk-row-main {
  flex: 1;
  min-width: 0;
}
.mk-row-title {
  display: block;
  font-weight: 500;
  overflow-wrap: anywhere;
}
.mk-row-detail {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 2px;
}
.mk-row-value {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: end;
}

/* Fields */
.mk-field {
  display: block;
  margin: 12px 0;
}
.mk-field > span {
  display: block;
  margin: 0 0 6px 4px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}
.mk-input,
.mk-select,
.mk-textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--control-line);
  border-radius: var(--radius-small);
  background: var(--surface);
  font-size: max(16px, 1rem);
}
.mk-select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.mk-textarea {
  min-height: 132px;
  resize: vertical;
  font-family: var(--mono);
  font-size: max(15px, 0.88rem);
  line-height: 1.5;
}
.mk-output {
  margin: 0;
  padding: 12px 14px;
  min-height: 48px;
  border-radius: var(--radius-small);
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 0.88rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: text;
  -webkit-user-select: text;
}
.mk-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 6px 4px 0;
}
.mk-note {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 8px 4px 0;
}

/* Buttons */
.mk-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 18px;
  border: 0;
  border-radius: var(--radius-small);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
.mk-button.secondary {
  background: var(--surface-2);
  color: var(--ink);
}
.mk-button.danger {
  background: transparent;
  color: var(--danger);
}
.mk-button.block {
  width: 100%;
}
.mk-button:disabled {
  opacity: 0.45;
}
.mk-button:active:not(:disabled) {
  transform: translateY(1px);
}
.mk-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}
.mk-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: 22px;
  background: transparent;
  color: var(--accent);
  font-size: 1.2rem;
}

.mk-empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
}
.mk-empty strong {
  display: block;
  color: var(--ink);
  font-size: 1.05rem;
  margin-bottom: 6px;
}

/* Sheet (a <dialog>) */
.mk-sheet {
  width: min(560px, 100%);
  max-height: min(92vh, 900px);
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 16px 16px 0 0;
  background: var(--canvas);
  color: var(--ink);
}
.mk-sheet::backdrop {
  background: rgba(0, 0, 0, 0.4);
}
@media (min-width: 600px) {
  .mk-sheet {
    margin: auto;
    border-radius: 16px;
  }
}
.mk-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 8px 0;
}
.mk-sheet-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  flex: 1;
  text-align: center;
}
.mk-sheet-header button {
  min-width: 72px;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 500;
}
.mk-sheet-header button.confirm {
  font-weight: 700;
}
.mk-sheet-body {
  padding: 4px var(--gutter) calc(24px + env(safe-area-inset-bottom));
}

/* Toast */
.mk-toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(30, 30, 32, 0.92);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 500;
  pointer-events: none;
  z-index: 10;
}

.mk-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
}
.mk-toggle input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
