:root {
  color-scheme: light;
  --paper: #fffaf0;
  --paper-deep: #f4eadb;
  --ink: #171511;
  --muted: #6d665c;
  --red: #c5413f;
  --red-dark: #9e302f;
  --green: #327052;
  --line: #d9cdbd;
  --shadow: 6px 6px 0 var(--ink);
  font-family: "Courier New", Courier, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(rgba(23, 21, 17, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 21, 17, 0.035) 1px, transparent 1px),
    var(--paper-deep);
  background-size: 20px 20px;
}

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

button {
  cursor: pointer;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  max-width: 1240px;
  margin: 0 auto;
  padding: 2rem 1.5rem 1.25rem;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1;
  letter-spacing: -0.055em;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 2.5vw, 2rem);
  letter-spacing: -0.04em;
}

h3 {
  margin-bottom: 0.2rem;
  font-size: 1rem;
  letter-spacing: -0.025em;
}

.eyebrow,
.step-label,
.preview-label {
  margin-bottom: 0.5rem;
  color: var(--red-dark);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.65rem 0.8rem;
  border: 2px solid var(--ink);
  background: var(--paper);
  font-size: 0.78rem;
  font-weight: 700;
}

.status-pill span {
  width: 0.65rem;
  height: 0.65rem;
  background: var(--red);
  box-shadow: 2px 2px 0 var(--ink);
}

.status-pill.is-online span {
  background: var(--green);
}

.text-button {
  border: 0;
  padding: 0.4rem;
  color: var(--muted);
  background: transparent;
  text-decoration: underline;
}

.page-shell {
  display: grid;
  gap: 2rem;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
}

.composer-card,
.status-card,
.login-card {
  border: 3px solid var(--ink);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.composer-card {
  padding: clamp(1.25rem, 3vw, 2rem);
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.75rem;
}

.muted,
.field-hint,
.preview-status {
  color: var(--muted);
}

.desktop-note {
  max-width: 34rem;
  margin-bottom: 0;
  font-size: 0.83rem;
  text-align: right;
}

.composer-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(360px, 0.92fr);
  gap: clamp(2rem, 4vw, 3.5rem);
  align-items: start;
}

.composer-form {
  display: grid;
  gap: 1rem;
}

.control-section {
  display: grid;
  gap: 1rem;
  border: 1px solid var(--line);
  padding: 1rem;
  background: rgba(255, 255, 255, 0.58);
}

.control-heading {
  display: flex;
  align-items: flex-start;
  gap: 0.8rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px dashed var(--line);
}

.control-heading p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.4;
}

.control-number {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 1.65rem;
  height: 1.65rem;
  color: #fff;
  background: var(--ink);
  box-shadow: 2px 2px 0 var(--red);
  font-size: 0.75rem;
  font-weight: 700;
}

.select-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

.field-group,
fieldset {
  display: grid;
  gap: 0.65rem;
  margin: 0;
  padding: 0;
  border: 0;
}

label,
legend {
  font-weight: 700;
}

.label-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

#character-count {
  color: var(--muted);
  font-size: 0.8rem;
}

textarea,
.login-form input,
select {
  width: 100%;
  border: 2px solid var(--ink);
  border-radius: 0;
  color: var(--ink);
  background: #fff;
  outline: none;
}

textarea {
  min-height: 9rem;
  padding: 1rem;
  resize: vertical;
  line-height: 1.55;
}

textarea:focus,
.login-form input:focus,
select:focus {
  box-shadow: 4px 4px 0 var(--red);
}

select {
  min-height: 3rem;
  padding: 0.65rem 2.5rem 0.65rem 0.75rem;
  appearance: none;
  cursor: pointer;
}

.select-shell {
  position: relative;
}

.select-shell::after {
  position: absolute;
  top: 50%;
  right: 0.85rem;
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  content: "";
  pointer-events: none;
  transform: translateY(-70%) rotate(45deg);
}

.field-hint {
  margin: 0;
  font-size: 0.76rem;
}

.choice-grid {
  display: grid;
  gap: 0.65rem;
}

.expression-grid {
  grid-template-columns: repeat(3, 1fr);
}

.character-grid {
  grid-template-columns: repeat(2, 1fr);
}

.layout-grid {
  grid-template-columns: repeat(2, 1fr);
}

.color-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choice-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-height: 3rem;
  padding: 0.7rem;
  border: 2px solid var(--line);
  background: #fff;
  font-size: 0.78rem;
  cursor: pointer;
}

.choice-card:has(input:checked) {
  border-color: var(--ink);
  box-shadow: 3px 3px 0 var(--red);
}

.choice-card:focus-within {
  outline: 2px dashed var(--red-dark);
  outline-offset: 3px;
}

.choice-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.choice-mark {
  flex: 0 0 auto;
  width: 0.8rem;
  height: 0.8rem;
  border: 2px solid var(--ink);
  background: var(--paper);
}

.choice-card input:checked + .choice-mark {
  background: var(--red);
}

.color-choice {
  min-height: 3rem;
}

.color-swatch {
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--ink);
}

.color-swatch.is-black {
  background: var(--ink);
}

.color-swatch.is-red {
  background: var(--red);
}

.character-choice {
  min-height: 3.6rem;
}

.character-glyph {
  position: relative;
  flex: 0 0 auto;
  width: 1.8rem;
  height: 1.8rem;
  border: 4px solid var(--ink);
  background: var(--paper);
  image-rendering: pixelated;
}

.character-glyph::before,
.character-glyph::after {
  position: absolute;
  content: "";
}

.character-glyph::before {
  top: 0.42rem;
  left: 0.28rem;
  width: 0.2rem;
  height: 0.2rem;
  background: var(--ink);
  box-shadow: 0.65rem 0 var(--ink);
}

.character-glyph::after {
  bottom: 0.25rem;
  left: 0.45rem;
  width: 0.45rem;
  height: 0.18rem;
  border-bottom: 2px solid var(--ink);
}

.glyph-cat {
  clip-path: polygon(0 18%, 0 0, 28% 18%, 50% 4%, 72% 18%, 100% 0, 100% 100%, 0 100%);
}

.glyph-bunny {
  border-top-width: 7px;
  border-radius: 45% 45% 0 0;
}

.glyph-bunny::after {
  top: -0.72rem;
  bottom: auto;
  left: 0.1rem;
  width: 0.32rem;
  height: 0.65rem;
  border: 3px solid var(--ink);
  background: var(--paper);
  box-shadow: 0.72rem 0 0 -1px var(--paper), 0.72rem 0 0 2px var(--ink);
}

.glyph-bear {
  border-radius: 30%;
  box-shadow: -0.25rem -0.22rem 0 -0.05rem var(--ink), 0.25rem -0.22rem 0 -0.05rem var(--ink);
}

.glyph-ghost {
  border-radius: 50% 50% 0 0;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 76% 78%, 53% 100%, 28% 78%, 0 100%);
}

.control-section.is-text-only #character-help::after {
  content: " Le mode Texte seul garde ces choix en mémoire, mais ne les affiche pas.";
}

.control-section.is-text-only fieldset {
  opacity: 0.42;
}

.layout-choice {
  min-height: 4.5rem;
}

.layout-mini {
  position: relative;
  flex: 0 0 auto;
  width: 2.8rem;
  height: 2rem;
  border: 2px solid var(--ink);
  background: var(--paper);
}

.layout-mini i,
.layout-mini b {
  position: absolute;
  display: block;
  background: var(--ink);
}

.layout-mini-character_right i {
  top: 0.45rem;
  left: 0.35rem;
  width: 1.1rem;
  height: 0.2rem;
  box-shadow: 0 0.4rem 0 var(--ink), 0 0.8rem 0 var(--ink);
}

.layout-mini-character_right b {
  top: 0.45rem;
  right: 0.35rem;
  width: 0.65rem;
  height: 1rem;
}

.layout-mini-character_centered i {
  top: 0.3rem;
  left: 1rem;
  width: 0.65rem;
  height: 0.65rem;
}

.layout-mini-character_centered b {
  bottom: 0.35rem;
  left: 0.5rem;
  width: 1.55rem;
  height: 0.2rem;
}

.layout-mini-character_left i {
  top: 0.45rem;
  right: 0.35rem;
  width: 1.1rem;
  height: 0.2rem;
  box-shadow: 0 0.4rem 0 var(--ink), 0 0.8rem 0 var(--ink);
}

.layout-mini-character_left b {
  top: 0.45rem;
  left: 0.35rem;
  width: 0.65rem;
  height: 1rem;
}

.layout-mini-text_only i {
  top: 0.5rem;
  left: 0.45rem;
  width: 1.55rem;
  height: 0.2rem;
  box-shadow: 0 0.42rem 0 var(--ink), 0 0.84rem 0 var(--ink);
}

.layout-mini-text_only b {
  display: none;
}

.primary-button {
  min-height: 3.25rem;
  border: 2px solid var(--ink);
  padding: 0.8rem 1rem;
  color: #fff;
  background: var(--red);
  box-shadow: 4px 4px 0 var(--ink);
  font-weight: 700;
}

.primary-button:hover {
  background: var(--red-dark);
}

.primary-button:active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 var(--ink);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.preview-column {
  position: sticky;
  top: 1rem;
}

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

.preview-heading span {
  color: var(--muted);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
}

.eink-frame {
  position: relative;
  width: 100%;
  border: 12px solid var(--ink);
  padding: 3%;
  background: #bdb6aa;
  box-shadow: 8px 8px 0 var(--red);
}

.eink-frame::before,
.eink-frame::after {
  position: absolute;
  top: -8px;
  width: 6px;
  height: 6px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--paper-deep);
  content: "";
}

.eink-frame::before {
  left: -8px;
}

.eink-frame::after {
  right: -8px;
}

.eink-frame img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid #7e786e;
  background: #fff;
  image-rendering: pixelated;
}

.preview-status {
  margin: 1rem 0 0;
  font-size: 0.76rem;
}

.preview-summary,
.history-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.preview-summary {
  margin-top: 0.75rem;
}

.preview-summary span,
.history-tags span {
  border: 1px solid var(--line);
  padding: 0.3rem 0.45rem;
  background: #fff;
  color: var(--muted);
  font-size: 0.65rem;
}

.status-card {
  display: grid;
  grid-template-columns: minmax(180px, 0.45fr) 1fr;
  gap: 2rem;
  padding: 1.5rem;
}

.status-intro {
  max-width: 19rem;
  margin: 0.75rem 0 0;
  font-size: 0.75rem;
  line-height: 1.45;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  border: 1px solid var(--line);
  background: var(--line);
}

.status-grid div {
  display: grid;
  gap: 0.4rem;
  padding: 1rem;
  background: #fff;
}

.status-grid span {
  color: var(--muted);
  font-size: 0.7rem;
}

.status-grid strong {
  font-size: 0.85rem;
}

.status-grid small {
  color: var(--muted);
  font-size: 0.65rem;
  line-height: 1.35;
}

.insights-section {
  padding: 1rem 0;
}

.insight-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.insight-card {
  position: relative;
  min-height: 10rem;
  overflow: hidden;
  border: 2px solid var(--ink);
  padding: 1.2rem;
  background: var(--paper);
}

.insight-card::after {
  position: absolute;
  right: -1.6rem;
  bottom: -1.6rem;
  width: 4rem;
  height: 4rem;
  border: 9px solid var(--red);
  content: "";
  transform: rotate(45deg);
}

.insight-card > span {
  color: var(--red-dark);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.insight-card strong {
  display: block;
  margin: 0.65rem 0 0.45rem;
  font-size: clamp(1.65rem, 4vw, 2.5rem);
  line-height: 1;
}

.insight-card p {
  max-width: 15rem;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.45;
}

.history-section {
  padding-top: 1rem;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
}

.history-card {
  overflow: hidden;
  border: 2px solid var(--ink);
  background: var(--paper);
}

.history-card.is-current {
  box-shadow: 5px 5px 0 var(--red);
}

.history-card > img {
  display: block;
  width: 100%;
  height: auto;
  border-bottom: 2px solid var(--ink);
  background: #fff;
  image-rendering: pixelated;
}

.history-content {
  padding: 1rem;
}

.history-content p {
  min-height: 2.4em;
  margin: 0.75rem 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.history-tags {
  margin-bottom: 0.9rem;
}

.history-content small {
  color: var(--muted);
}

.history-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.history-meta span {
  padding: 0.25rem 0.4rem;
  color: #fff;
  background: var(--red);
  font-size: 0.65rem;
  font-weight: 700;
}

.restore-button {
  border: 0;
  padding: 0;
  color: var(--red-dark);
  background: transparent;
  font-size: 0.75rem;
  font-weight: 700;
  text-decoration: underline;
}

.alert {
  margin: 0;
  border-left: 5px solid var(--red);
  padding: 0.75rem;
  background: #f9d8d3;
  color: #651d1d;
  font-size: 0.8rem;
}

.is-hidden {
  display: none;
}

.login-page {
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.login-card {
  width: min(100%, 430px);
  padding: clamp(1.5rem, 6vw, 3rem);
}

.login-card h1 {
  margin-bottom: 1.25rem;
}

.login-form {
  display: grid;
  gap: 0.8rem;
  margin-top: 1.5rem;
}

.login-form input {
  min-height: 3.25rem;
  padding: 0.8rem;
}

.pixel-heart {
  width: 16px;
  height: 16px;
  margin-bottom: 1.5rem;
  background: var(--red);
  box-shadow:
    16px 0 var(--red),
    -8px 8px var(--red),
    0 8px var(--red),
    8px 8px var(--red),
    16px 8px var(--red),
    24px 8px var(--red),
    0 16px var(--red),
    8px 16px var(--red),
    16px 16px var(--red),
    8px 24px var(--red);
  transform: scale(0.55);
  transform-origin: top left;
}

@media (max-width: 900px) {
  .composer-grid,
  .status-card {
    grid-template-columns: 1fr;
  }

  .preview-column {
    position: static;
  }

  .status-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .history-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .insight-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 620px) {
  .site-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 1rem;
    padding-top: 1.25rem;
  }

  .header-actions {
    align-items: center;
    flex-direction: row;
    justify-content: space-between;
    width: 100%;
  }

  .status-pill {
    font-size: 0.65rem;
  }

  .desktop-note {
    display: none;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.6rem;
  }

  .history-grid {
    grid-template-columns: 1fr;
  }

  .select-grid,
  .layout-grid,
  .character-grid,
  .expression-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-grid {
    grid-template-columns: 1fr 1fr;
  }

  .insight-grid {
    grid-template-columns: 1fr;
  }

  .insight-card {
    min-height: 8rem;
  }

  .composer-card,
  .status-card {
    box-shadow: 4px 4px 0 var(--ink);
  }

  .page-shell {
    padding-inline: 0.9rem;
  }

  .composer-card {
    padding: 1rem;
  }

  .control-section {
    padding: 0.85rem;
  }

  .choice-card {
    padding: 0.6rem;
  }

  .character-choice,
  .layout-choice {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.45rem;
  }

  .character-choice .choice-mark,
  .layout-choice .choice-mark {
    position: absolute;
    top: 0.55rem;
    right: 0.55rem;
  }

  .preview-heading span {
    display: none;
  }
}

@media (max-width: 390px) {
  .select-grid,
  .layout-grid,
  .character-grid,
  .color-grid,
  .status-grid {
    grid-template-columns: 1fr;
  }
}
