:root {
  --bg: #f4efe6;
  --panel: rgba(255, 253, 248, 0.94);
  --ink: #1f1b16;
  --muted: #6b6257;
  --line: #d6c7b2;
  --accent: #b6461d;
  --accent-strong: #8e3414;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Noto Sans JP", "Hiragino Sans", "Yu Gothic", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(182, 70, 29, 0.16), transparent 24rem),
    linear-gradient(180deg, #f7f2ea 0%, var(--bg) 100%);
}

a {
  color: inherit;
  text-decoration: none;
}

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

input,
select,
textarea {
  width: 100%;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: #fff;
  color: var(--ink);
}

input[readonly] {
  background: #ece5da;
  color: #7a6e61;
  cursor: default;
}

textarea {
  min-height: 9rem;
  resize: vertical;
}

.message-editor {
  min-height: 18rem;
}

h1 {
  margin: 0.9rem 0 0.4rem;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 0.95;
}

h2 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel-heading h2 {
  margin: 0;
}

label {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.9rem;
  font-weight: 700;
}

.inline-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

.inline-toggle input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: var(--accent);
}

.shell {
  width: min(960px, calc(100vw - 2rem));
  margin: 0 auto;
  padding: 2rem 0 4rem;
}

.shell-narrow {
  width: min(760px, calc(100vw - 2rem));
}

.topbar {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.nav-link,
.primary,
.ghost,
.preset-button {
  border-radius: 999px;
  transition: transform 120ms ease;
}

.nav-link:hover,
.primary:hover,
.ghost:hover,
.preset-button:hover {
  transform: translateY(-1px);
}

.nav-link {
  display: inline-flex;
  align-items: center;
  padding: 0.7rem 1rem;
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.9);
  font-size: 0.92rem;
  font-weight: 700;
}

.hero,
.panel {
  border: 1px solid var(--line);
  border-radius: 1.5rem;
  background: var(--panel);
  box-shadow: 0 24px 60px rgba(31, 27, 22, 0.08);
}

.hero {
  margin-bottom: 1rem;
  padding: 1.5rem;
}

.panel {
  padding: 1.25rem;
}

.eyebrow {
  display: inline-block;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: rgba(182, 70, 29, 0.12);
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.lede,
.hint,
.status,
.history-meta {
  color: var(--muted);
}

.app-grid,
.settings-grid,
.message-grid {
  display: grid;
  gap: 1rem;
}

.app-grid {
  grid-template-columns: minmax(320px, 360px) minmax(0, 1fr);
}

.settings-grid {
  margin-top: 1rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.message-grid {
  margin-top: 1rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.row,
.split-stack {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.8rem;
  margin-top: 0.9rem;
}

.split-aim-line {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 0.8rem;
  align-items: start;
}

.aim-code-input {
  text-align: center;
}

.compact-readonly {
  font-size: 0.75rem;
  padding: 0.45rem 0.65rem;
  border-radius: 0.7rem;
  min-height: 2.1rem;
}

.actions,
.preset-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

.primary,
.ghost,
.preset-button {
  cursor: pointer;
}

.primary {
  padding: 0.85rem 1.25rem;
  border: 0;
  background: var(--accent);
  color: #fff7f0;
  font-weight: 700;
}

.ghost,
.preset-button {
  padding: 0.85rem 1.25rem;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.preview {
  min-height: 640px;
  padding: 1.5rem;
  border: 1px dashed var(--line);
  border-radius: 1.25rem;
  background: linear-gradient(135deg, rgba(182, 70, 29, 0.04), transparent), #fff;
}

.preview-card {
  display: flex;
  justify-content: center;
  text-align: center;
}

.print-layout {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.print-main {
  flex: 1 1 auto;
  width: 100%;
}

.print-message,
.message-preview {
  min-height: 42%;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: rgba(244, 239, 230, 0.45);
  text-align: left;
}

.message-scaled {
  --message-font-size: 14px;
  font-size: var(--message-font-size);
  line-height: 1.45;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  margin: 0 0 0.6rem;
  line-height: 1.2;
}

.markdown-body h1 {
  font-size: 1.35rem;
}

.markdown-body h2 {
  font-size: 1.1rem;
}

.markdown-body h3 {
  font-size: 1rem;
}

.message-scaled.markdown-body h1 {
  font-size: calc(var(--message-font-size) * 1.35);
}

.message-scaled.markdown-body h2 {
  font-size: calc(var(--message-font-size) * 1.15);
}

.message-scaled.markdown-body h3 {
  font-size: calc(var(--message-font-size) * 1.05);
}

.markdown-body p,
.markdown-body ul {
  margin: 0 0 0.65rem;
}

.markdown-body ul {
  padding-left: 1.2rem;
}

.markdown-body li {
  list-style: disc;
}

.markdown-body code {
  padding: 0.08rem 0.3rem;
  border-radius: 0.35rem;
  background: rgba(31, 27, 22, 0.08);
  font-family: "SFMono-Regular", Consolas, monospace;
}

.markdown-qr {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.markdown-qr-graphic {
  width: min(180px, 100%);
}

.markdown-qr-graphic svg {
  display: block;
  width: 100%;
  height: auto;
}

.markdown-qr-text {
  margin: 0;
  word-break: break-word;
  text-align: center;
}

.preview-paper {
  width: min(100%, 420px);
  aspect-ratio: 105 / 148;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 18px 40px rgba(31, 27, 22, 0.14);
}

.preview-card svg {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

.status-panel {
  margin-top: 1rem;
}

.status-panel .status {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: #fff;
}

.status[data-tone="error"] {
  color: #9a1f1f;
}

.history {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
}

.history button {
  width: 100%;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.history-title {
  display: block;
  margin-bottom: 0.2rem;
  font-weight: 700;
}

.print-sheet {
  display: none;
}

@page {
  size: A6 portrait;
  margin: 0;
}

@media (max-width: 800px) {
  .app-grid,
  .settings-grid,
  .message-grid,
  .split-aim-line {
    grid-template-columns: 1fr;
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .preview {
    min-height: 520px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .shell {
    width: auto;
    margin: 0;
    padding: 0;
  }

  .shell > :not(.print-sheet) {
    display: none !important;
  }

  .print-sheet {
    display: block !important;
    width: 105mm;
    min-height: 148mm;
  }
}
