* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
button, input { touch-action: manipulation; font-family: inherit; }

:root {
  --bg:            #ffffff;
  --bg-elev:       #fafafa;
  --bg-composer:   #fafafa;
  --text:          #171717;
  --text-secondary:#404040;
  --text-muted:    #737373;
  --text-dim:      #a3a3a3;
  --border:        #e5e5e5;
  --border-strong: #d4d4d4;
  --hover:         #f5f5f5;
  --pressed:       #efefef;
  --accent:        #171717;
  --accent-hover:  #000000;
  --error:         #b91c1c;
  --ink:           #171717;

  --ui:   'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;

  --radius:      8px;
  --radius-lg:   12px;
  --shadow-sm:   0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow:      0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--ui);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
}

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* -------- Topbar -------- */

.topbar {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(env(safe-area-inset-top), 10px);
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 3;
}

.topbar-title {
  font-family: var(--ui);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.1px;
  color: var(--text);
  text-align: center;
}

.topbar-date {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: 6px;
  transition: background 120ms ease, color 120ms ease;
}
.icon-btn:hover  { background: var(--hover);   color: var(--text); }
.icon-btn:active { background: var(--pressed); }

/* -------- Feed -------- */

.feed {
  position: relative;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 24px 20px 40px;
  background: var(--bg);
}

.feed-inner {
  max-width: 680px;
  margin: 0 auto;
}

/* Empty state */

.empty-state {
  padding-top: 60px;
  text-align: center;
  color: var(--text-muted);
  animation: fadeIn 400ms ease both;
}
.empty-state p { margin: 0; font-size: 15px; }
.empty-state .empty-hint {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 4px;
}
.empty-state.hidden { display: none; }

/* -------- Entry -------- */

.entry {
  padding: 20px 0 28px;
  border-top: 1px solid var(--border);
  animation: entryIn 350ms cubic-bezier(.22,.61,.36,1) both;
}
.entry:first-of-type { border-top: none; padding-top: 4px; }

.entry-meta {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
  font-variant-numeric: tabular-nums;
}

.entry-question {
  font-size: 17px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--text);
  margin-bottom: 14px;
  letter-spacing: -0.1px;
  overflow-wrap: anywhere;
  word-break: break-word;
  animation: fadeIn 260ms ease both;
}
.entry-question:empty { display: none; }

.entry-answer {
  font-size: 15.5px;
  line-height: 1.7;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
  word-break: break-word;
  min-height: 24px;
  transition: opacity 320ms ease;
  opacity: 0;
}
.entry-answer.revealed { opacity: 1; }
.entry-answer.error    { color: var(--error); }

/* Thinking placeholder */
.thinking { border-top: 1px solid var(--border); }
.thinking.hidden { display: none; }
.thinking .entry-meta { margin: 0; }
.thinking-dots::after {
  content: '';
  display: inline-block;
  margin-left: 2px;
  animation: dots 1.4s steps(1) infinite;
}
@keyframes dots {
  0%   { content: '';    }
  25%  { content: '.';   }
  50%  { content: '..';  }
  75%  { content: '...'; }
  100% { content: '';    }
}

@keyframes entryIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* -------- Composer -------- */

.composer {
  position: relative;
  background: var(--bg-composer);
  border-top: 1px solid var(--border);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  z-index: 3;
}

.composer-inner {
  max-width: 680px;
  margin: 0 auto;
}

.canvas-wrap {
  position: relative;
  height: 180px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg);
  overflow: hidden;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}
.canvas-wrap:focus-within,
.canvas-wrap.active {
  border-color: #a3a3a3;
  box-shadow: 0 0 0 3px rgba(23, 23, 23, 0.05);
}

@media (min-width: 700px) and (pointer: coarse) {
  .canvas-wrap { height: 220px; }
}
@media (min-width: 900px) and (pointer: coarse) and (orientation: landscape) {
  .canvas-wrap { height: 240px; }
}

#board {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  cursor: crosshair;
  background: transparent;
}

.canvas-hint {
  position: absolute;
  top: 14px;
  left: 16px;
  font-size: 13px;
  color: var(--text-dim);
  pointer-events: none;
  transition: opacity 200ms ease;
  font-family: var(--ui);
}
.canvas-hint.hidden { opacity: 0; }

.composer-tools {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 10px 0 0;
}

.spacer { flex: 1; }

.tool {
  padding: 0 12px;
  height: 34px;
  font-family: var(--ui);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.tool:hover:not(:disabled)  { background: var(--hover);   color: var(--text); }
.tool:active:not(:disabled) { background: var(--pressed); }
.tool:disabled { opacity: 0.4; cursor: not-allowed; }

.status {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  margin: 0 8px;
  font-variant-numeric: tabular-nums;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.primary {
  height: 34px;
  padding: 0 18px;
  font-family: var(--ui);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.1px;
  color: #ffffff;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 120ms ease, transform 80ms ease;
  box-shadow: var(--shadow-sm);
}
.primary:hover:not(:disabled)  { background: var(--accent-hover); }
.primary:active:not(:disabled) { transform: translateY(0.5px); }
.primary:disabled { opacity: 0.45; cursor: not-allowed; }

/* -------- Focus rings (keyboard only) -------- */

button:focus-visible,
.icon-btn:focus-visible {
  outline: 2px solid #171717;
  outline-offset: 2px;
}

/* -------- Reduced motion -------- */

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

/* -------- iPad / tablet -------- */

@media (min-width: 700px) and (pointer: coarse) {
  body { font-size: 15.5px; }
  .topbar { padding: 12px 20px; }
  .topbar-title { font-size: 15px; }
  .entry-question { font-size: 18px; }
  .entry-answer   { font-size: 16px; line-height: 1.7; }
  .tool    { font-size: 14px; height: 36px; padding: 0 14px; }
  .primary { font-size: 14px; height: 36px; padding: 0 20px; }
  .composer { padding: 14px 20px calc(14px + env(safe-area-inset-bottom)); }
}
