:root {
  --paper: #f6f1e6;
  --paper-edge: #ede5d2;
  --ink: #211e1b;
  --ink-soft: #6b655c;
  --accent: #a8792f;
  --accent-strong: #6e4e1e;
  --rule: #ddd2ba;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(33, 30, 27, 0.08);
  --focus: #3d6b8c;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.4;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- header ---------- */

.page-header {
  padding: 28px 20px 16px;
  max-width: 640px;
  margin: 0 auto;
}

.page-header h1 {
  margin: 0;
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  font-style: italic;
  font-size: 32px;
  font-weight: 600;
  color: var(--ink);
}

/* ---------- layout ---------- */

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field > label,
legend {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
  padding: 0;
}

/* ---------- input ---------- */

#input {
  width: 100%;
  min-height: 130px;
  resize: vertical;
  padding: 14px;
  font-size: 16px; /* prevents iOS auto-zoom on focus */
  font-family: inherit;
  color: var(--ink);
  background: #fffdf8;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

#input::placeholder {
  color: #a39c8d;
}

#input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

/* ---------- style picker ---------- */

fieldset.style-picker {
  border: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  position: relative;
}

.chip input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.chip label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 16px;
  min-height: 44px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: #fffdf8;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.chip .glyph-sample {
  font-size: 18px;
  line-height: 1;
}

.chip .style-name {
  font-size: 13px;
  color: var(--ink-soft);
}

.chip input:checked + label {
  border-color: var(--accent);
  background: #fbf3e3;
}

.chip input:checked + label .style-name {
  color: var(--accent-strong);
  font-weight: 600;
}

.chip input:focus-visible + label {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- output ---------- */

.output-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.hint {
  font-size: 12px;
  color: #a39c8d;
}

.output {
  min-height: 90px;
  padding: 14px;
  font-size: 18px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: #fffdf8;
  box-shadow: var(--shadow);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.output:empty::before {
  content: "Your text will appear here.";
  color: #a39c8d;
  font-size: 16px;
}

/* ---------- action bar ---------- */

.action-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 10px;
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, rgba(246, 241, 230, 0), var(--paper) 22%);
  max-width: 640px;
  margin: 0 auto;
}

.btn {
  flex: 1;
  min-height: 48px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #fffdf8;
}

.btn-primary:hover {
  background: var(--accent-strong);
}

.btn-ghost {
  background: transparent;
  border-color: var(--rule);
  color: var(--ink-soft);
}

.btn-ghost:hover {
  background: var(--paper-edge);
}

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

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .btn {
    transition: none;
  }
}

/* ---------- small screens fine-tuning ---------- */

@media (max-width: 380px) {
  .page-header h1 {
    font-size: 28px;
  }
}
