:root {
  --bg: #efe5cf;
  --bg-pattern: #e7dbc0;
  --surface: #fffaf0;
  --surface-2: #f7efdd;
  --ink: #2b2118;
  --ink-soft: #6b5a48;
  --line: #2b2118;
  --line-soft: #d8c9a8;
  --accent: #1f4e5f;
  --accent-ink: #f4ecd8;
  --shadow: #2b2118;

  --s-todo: #c27c0e;
  --s-todo-bg: #fbe9c6;
  --s-ask: #a23b2a;
  --s-ask-bg: #f8d9d2;
  --s-precise: #1f6f8b;
  --s-precise-bg: #d4ecf3;
  --s-done: #3c7a3b;
  --s-done-bg: #dcefd6;
  --s-int: #6b5a48;
  --s-int-bg: #e8e0d0;

  --radius: 4px;
  --pixel: 3px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17130e;
    --bg-pattern: #1c1711;
    --surface: #231d16;
    --surface-2: #2b241b;
    --ink: #efe6d2;
    --ink-soft: #b3a48c;
    --line: #5c4d3a;
    --line-soft: #3b3226;
    --accent: #6fb3c8;
    --accent-ink: #0f1a1e;
    --shadow: #000;
    --s-todo: #e9a73a;
    --s-todo-bg: #3a2a10;
    --s-ask: #ec7a66;
    --s-ask-bg: #40201a;
    --s-precise: #6cc0dd;
    --s-precise-bg: #14313b;
    --s-done: #82c77f;
    --s-done-bg: #1d3320;
    --s-int: #b3a48c;
    --s-int-bg: #2e281f;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background-color: var(--bg);
  background-image: radial-gradient(var(--bg-pattern) 1.5px, transparent 1.5px);
  background-size: 18px 18px;
  color: var(--ink);
  font: 16px/1.55 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}

.wrap {
  max-width: 920px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

h1,
h2,
.label,
.kicker,
.progress-num,
.seal {
  font-family: "Pixelify Sans", Inter, system-ui, sans-serif;
}

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

.muted {
  color: var(--ink-soft);
}
.small {
  font-size: 0.875rem;
}

.loading,
.empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 48px 0;
}

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

.top {
  background: var(--accent);
  color: var(--accent-ink);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--pixel) var(--pixel) 0 var(--shadow);
  padding: 20px 22px;
  margin-bottom: 18px;
}
.top-row {
  display: flex;
  gap: 20px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}
.kicker {
  margin: 0;
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.8;
}
.top h1 {
  margin: 2px 0 4px;
  font-size: clamp(1.7rem, 5vw, 2.3rem);
  line-height: 1.1;
}
.hello {
  margin: 0;
  opacity: 0.92;
}
.progress {
  display: grid;
  grid-template-columns: auto auto;
  align-items: baseline;
  gap: 0 8px;
  min-width: 160px;
}
.progress-num {
  font-size: 2rem;
  line-height: 1;
}
.progress-num small {
  font-size: 1rem;
  opacity: 0.8;
}
.progress-label {
  font-size: 0.85rem;
  opacity: 0.85;
}
.bar {
  grid-column: 1 / -1;
  height: 12px;
  margin-top: 8px;
  border: 2px solid var(--accent-ink);
  background: color-mix(in srgb, var(--accent-ink) 15%, transparent);
}
.bar i {
  display: block;
  height: 100%;
  background: var(--accent-ink);
  transition: width 0.4s;
}

/* ---------- help ---------- */

.help {
  background: var(--surface);
  border: 2px dashed var(--line-soft);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 18px;
}
.help h2 {
  margin: 0 0 6px;
  font-size: 1.15rem;
}
.help ol {
  margin: 0 0 8px;
  padding-left: 22px;
}
.help li {
  margin: 4px 0;
}
.help p {
  margin: 0 0 6px;
}

/* ---------- toolbar ---------- */

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
  position: sticky;
  top: 0;
  z-index: 5;
  margin-inline: -6px;
  padding: 10px 6px;
  background: var(--bg);
}
.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.chips::-webkit-scrollbar {
  display: none;
}
.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 2px solid var(--line-soft);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
}
.chip .count {
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  font-weight: 600;
}
.chip.on {
  border-color: var(--line);
  background: var(--ink);
  color: var(--surface);
}
.chip.on .count {
  color: inherit;
  opacity: 0.75;
}
.search {
  width: 100%;
  border: 2px solid var(--line-soft);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 9px 12px;
}
.search:focus,
.field:focus {
  outline: none;
  border-color: var(--accent);
}

/* ---------- status pills ---------- */

[data-status="a_repondre"] {
  --s: var(--s-todo);
  --s-bg: var(--s-todo-bg);
}
[data-status="precision_demandee"] {
  --s: var(--s-ask);
  --s-bg: var(--s-ask-bg);
}
[data-status="precise"] {
  --s: var(--s-precise);
  --s-bg: var(--s-precise-bg);
}
[data-status="repondu"] {
  --s: var(--s-done);
  --s-bg: var(--s-done-bg);
}
[data-status="integre"] {
  --s: var(--s-int);
  --s-bg: var(--s-int-bg);
}
.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  color: var(--s);
  background: var(--s-bg);
  border: 1.5px solid var(--s);
}
.chip[data-status]:not(.on) {
  border-color: color-mix(in srgb, var(--s) 45%, var(--line-soft));
}

/* ---------- tickets ---------- */

.part {
  font-size: 1.2rem;
  margin: 26px 0 10px;
}
.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ticket {
  background: var(--surface);
  border: 2px solid var(--line);
  border-left: 8px solid var(--s);
  border-radius: var(--radius);
  box-shadow: var(--pixel) var(--pixel) 0 var(--shadow);
  transition: transform 0.08s;
}
.ticket:not(.open):hover {
  transform: translate(-1px, -1px);
  box-shadow: calc(var(--pixel) + 1px) calc(var(--pixel) + 1px) 0 var(--shadow);
}
.ticket-head {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border: 0;
  background: none;
  text-align: left;
  padding: 14px 16px;
  cursor: pointer;
}
.label {
  flex: none;
  min-width: 3.2em;
  font-size: 1.1rem;
  line-height: 1.35;
  color: var(--accent);
}
.head-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.title {
  font-weight: 600;
  line-height: 1.35;
}
.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  font-size: 0.82rem;
  color: var(--ink-soft);
}
.ver {
  font-weight: 600;
}
.dot {
  flex: none;
  align-self: center;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--s-ask);
  color: #fff;
  padding: 2px 7px;
  border-radius: 999px;
}
.chev {
  flex: none;
  align-self: center;
  width: 10px;
  height: 10px;
  border-right: 3px solid var(--ink-soft);
  border-bottom: 3px solid var(--ink-soft);
  transform: rotate(45deg);
  margin: 0 4px 4px;
  transition: transform 0.15s;
}
.ticket.open .chev {
  transform: rotate(-135deg);
  margin-bottom: -4px;
}
.ticket-body {
  border-top: 2px dashed var(--line-soft);
  padding: 4px 18px 18px;
}

/* ---------- question body ---------- */

.version-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  font-size: 0.85rem;
  margin: 12px 0 4px;
}
.version-pick select,
.status-pick select {
  border: 2px solid var(--line-soft);
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 3px 6px;
  font-size: 0.85rem;
}
.old-warning {
  color: var(--s-ask);
  font-weight: 600;
}
.md {
  overflow-wrap: anywhere;
}
.md.old {
  opacity: 0.75;
}
.md p {
  margin: 10px 0;
}
.md ul,
.md ol {
  padding-left: 22px;
  margin: 8px 0;
}
.md li {
  margin: 4px 0;
}
.md strong {
  font-weight: 650;
}
.md em {
  color: var(--ink-soft);
}
.md hr {
  border: 0;
  border-top: 2px dashed var(--line-soft);
  margin: 16px 0;
}
.md table {
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 0.9rem;
  max-width: 100%;
}
.md th,
.md td {
  border: 1.5px solid var(--line-soft);
  padding: 6px 10px;
  vertical-align: top;
  text-align: left;
}
.md th {
  background: var(--surface-2);
  white-space: nowrap;
}
.md td:nth-child(2),
.md td:nth-child(3) {
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.md code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.9em;
}

/* ---------- thread ---------- */

.thread {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.thread h4,
.composer h4 {
  margin: 0;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}
.msg {
  max-width: min(640px, 92%);
  border: 2px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 8px 12px;
  background: var(--surface-2);
}
.msg.from-author {
  align-self: flex-start;
}
.msg.from-dev {
  align-self: flex-end;
}
.msg.answer {
  border-color: var(--s-done);
  background: var(--s-done-bg);
}
.msg.ask {
  border-color: var(--s-ask);
  background: var(--s-ask-bg);
}
.msg.precision {
  border-color: var(--s-precise);
  background: var(--s-precise-bg);
}
.msg-head {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 0.82rem;
  margin-bottom: 2px;
}
.msg-head .kind {
  font-weight: 600;
  color: var(--ink-soft);
}
.msg-head time {
  margin-left: auto;
  color: var(--ink-soft);
}
.msg-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.event {
  align-self: center;
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
  text-align: center;
}

/* ---------- composer ---------- */

.composer {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 2px dashed var(--line-soft);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.composer > p {
  margin: 0;
}
.options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.opt {
  min-width: 40px;
  height: 36px;
  font-family: "Pixelify Sans", Inter, sans-serif;
  font-size: 1.05rem;
  border: 2px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 2px 2px 0 var(--shadow);
  cursor: pointer;
}
.opt:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}
.field {
  width: 100%;
  border: 2px solid var(--line-soft);
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 10px 12px;
  resize: vertical;
}
.field.mono {
  font: 0.85rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.editing {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}
.editing p {
  margin: 0;
  font-size: 0.85rem;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.spacer {
  flex: 1;
}
.btn {
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 16px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--shadow);
}
.btn:active:not(:disabled) {
  transform: translate(2px, 2px);
  box-shadow: none;
}
.btn:disabled {
  opacity: 0.55;
  cursor: progress;
}
.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
}
.btn.ghost {
  background: var(--surface);
}
.link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  font-size: inherit;
}

/* ---------- misc ---------- */

.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  margin-top: 40px;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.locked {
  max-width: 460px;
  margin: 14vh auto 0;
  padding: 32px 24px;
  text-align: center;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--pixel) var(--pixel) 0 var(--shadow);
}
.locked h1 {
  margin: 12px 0 8px;
}
.seal {
  width: 64px;
  height: 64px;
  margin: 0 auto;
  display: grid;
  place-items: center;
  font-size: 2.4rem;
  background: var(--accent);
  color: var(--accent-ink);
  border: 2px solid var(--line);
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translate(-50%, 140%);
  max-width: calc(100% - 32px);
  background: var(--ink);
  color: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-weight: 500;
  box-shadow: var(--pixel) var(--pixel) 0 var(--shadow);
  transition:
    transform 0.2s,
    visibility 0.2s;
  visibility: hidden;
  z-index: 20;
}
#toast.show {
  transform: translate(-50%, 0);
  visibility: visible;
}
#toast[data-kind="error"] {
  background: var(--s-ask);
  color: #fff;
}
#toast[data-kind="ok"] {
  background: var(--s-done);
  color: #fff;
}

@media (max-width: 560px) {
  .wrap {
    padding-top: 16px;
  }
  .top {
    padding: 16px;
  }
  .ticket-head {
    padding: 12px;
    gap: 10px;
  }
  .ticket-body {
    padding: 4px 12px 14px;
  }
  .label {
    min-width: 2.6em;
  }
  .actions .btn {
    flex: 1 1 auto;
  }
  .msg {
    max-width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
