/* txt.2-38.com — spec §4.2
 *
 * No card, no paper shadow, no fake Apple window chrome. The screen width is
 * used directly. Body text uses a system monospace stack with a Japanese
 * fallback, base 16 CSS px, line-height 1.6.
 */

:root {
  --bg: #ffffff;
  --fg: #1c1c1e;
  --muted: #6b6b70;
  --line: #d9d9de;
  --accent: #0a84ff;
  --danger: #c0392b;
  --pad-inline: 16px;
  --footer-height: 56px;
}

@media (min-width: 720px) {
  :root {
    --pad-inline: 32px;
  }
}

@media (min-width: 1100px) {
  :root {
    --pad-inline: 48px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111114;
    --fg: #e7e7ea;
    --muted: #9a9aa2;
    --line: #2c2c31;
    --accent: #4c9aff;
    --danger: #ff6b5e;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
}

body {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Yu Gothic",
    "Hiragino Kaku Gothic ProN", Meiryo, monospace;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

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

/* ------------------------------------------------------------------ */
/* Editor                                                              */
/* ------------------------------------------------------------------ */

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.editor {
  flex: 1;
  padding: 24px var(--pad-inline) 0;
  /* Trailing space so the last line is never hidden behind the footer or the
     software keyboard (spec §4.2). */
  padding-bottom: calc(var(--footer-height) + env(safe-area-inset-bottom, 0px) + 40vh);
  outline: none;
  overflow-anchor: none;
}

.editor .ProseMirror {
  outline: none;
  min-height: 100%;
  white-space: pre-wrap;
  word-break: break-word;
  caret-color: var(--fg);
  /* Avoid clipping near the caret and never transform the editing surface:
     both are IME hazards (spec §4.2). */
  transform: none;
  contain: none;
}

.editor .ProseMirror p {
  margin: 0;
}

.editor .txt-media {
  margin: 12px 0;
  max-width: 100%;
}

.editor .txt-media img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

.editor .txt-media video,
.editor .txt-media audio {
  display: block;
  max-width: 100%;
}

.editor .txt-media-placeholder {
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 12px;
  color: var(--muted);
  font-size: 14px;
}

.editor .ProseMirror-selectednode {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------ */
/* Controls                                                            */
/* ------------------------------------------------------------------ */

.controls {
  position: fixed;
  inset: auto 0 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px var(--pad-inline);
  padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  min-height: var(--footer-height);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
}

.icon-button:hover {
  background: color-mix(in srgb, var(--fg) 10%, transparent);
}

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

.icon-button svg {
  width: 22px;
  height: 22px;
}

.sync-status {
  flex: 1;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  min-height: 1.2em;
}

.sync-status[data-state="error"],
.sync-status[data-state="conflict"] {
  color: var(--danger);
}

.sync-status[data-state="offline"] {
  color: var(--muted);
  font-weight: 600;
}

.attach-progress {
  position: fixed;
  left: var(--pad-inline);
  right: var(--pad-inline);
  bottom: calc(var(--footer-height) + env(safe-area-inset-bottom, 0px) + 8px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.attach-item {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-size: 13px;
}

.attach-item progress {
  flex: 1;
  height: 6px;
}

.attach-item button {
  border: none;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font: inherit;
  padding: 4px 6px;
  min-height: 32px;
}

/* ------------------------------------------------------------------ */
/* Gate                                                                */
/* ------------------------------------------------------------------ */

.gate {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px var(--pad-inline);
}

.gate-card {
  width: min(560px, 100%);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.gate-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  line-height: 1.5;
}

.gate-body {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.gate-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.button {
  font: inherit;
  font-size: 15px;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.button.secondary {
  background: transparent;
  border-color: var(--line);
  color: var(--fg);
}

.button:disabled {
  opacity: 0.5;
  cursor: default;
}

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

.gate-details {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  font-size: 14px;
}

.gate-details summary {
  cursor: pointer;
  color: var(--muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 12px 0;
}

.field textarea {
  font: inherit;
  font-size: 13px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--fg);
  resize: vertical;
}

.gate-footnote {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  min-height: 1.2em;
}

.gate-footnote[data-state="error"] {
  color: var(--danger);
}

/* ------------------------------------------------------------------ */
/* Dialog & toast                                                      */
/* ------------------------------------------------------------------ */

.dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  max-width: min(560px, calc(100vw - 32px));
  background: var(--bg);
  color: var(--fg);
}

.dialog::backdrop {
  background: rgb(0 0 0 / 40%);
}

.dialog-title {
  margin: 0 0 12px;
  font-size: 17px;
}

.dialog-body {
  font-size: 14px;
  color: var(--fg);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
}

.dialog-actions .button {
  flex: 1;
  min-width: 140px;
}

.dialog pre {
  white-space: pre-wrap;
  word-break: break-all;
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin: 0;
  max-height: 200px;
  overflow: auto;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--footer-height) + env(safe-area-inset-bottom, 0px) + 16px);
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  max-width: calc(100vw - 32px);
}

/* Menus are native popovers so IME focus is never stolen by custom widgets. */
.menu {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px;
  background: var(--bg);
  color: var(--fg);
  min-width: 220px;
}

.menu button {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  min-height: 40px;
}

.menu button:hover {
  background: color-mix(in srgb, var(--fg) 8%, transparent);
}
