/* ircmarkkina — utilitarian, academic, mummoystävällinen.
 *
 * Atkinson Hyperlegible + Verdana fallback. Golden-ratio scale.
 * Cool-paper neutrals (not warm beige). Every OKLCH color paired with a
 * hex fallback via @supports. Works back to Firefox 78 / Safari 13 /
 * Chromium 88 / any evergreen Edge.
 */

/* ============================================================== */
/*  [hidden] must always win                                       */
/* ============================================================== */
[hidden] { display: none !important; }

/* ============================================================== */
/*  Fonts                                                          */
/* ============================================================== */
@font-face {
  font-family: "Atkinson Hyperlegible";
  src: url("/fonts/AtkinsonHyperlegible-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible";
  src: url("/fonts/AtkinsonHyperlegible-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ============================================================== */
/*  Tokens — hex defaults; OKLCH upgrades where supported          */
/* ============================================================== */
:root {
  --fs-xs:   0.772rem;
  --fs-sm:   0.875rem;
  --fs-base: 1rem;
  --fs-md:   1.25rem;
  --fs-lg:   1.618rem;
  --fs-xl:   2.618rem;

  --lh-tight: 1.25;
  --lh-body:  1.5;

  --measure: 66ch;

  /* Cool-paper neutrals */
  --bg:        #fbfbfc;
  --bg-sunk:   #f1f2f4;
  --bg-raise:  #ffffff;
  --ink:       #1c1f26;
  --ink-soft:  #5a6072;
  --rule:      #dbdde3;

  --accent:    #2f5aa8;
  --accent-ink:#ffffff;
  --ok:        #2c7a4b;
  --warn:      #b08900;
  --danger:    #a32727;

  --role-buy-raha:        #2a5aa7;
  --role-buy-vaihto:      #405d87;
  --role-buy-ilmaiseksi:  #7a8fb5;
  --role-sell-raha:       #a55a00;
  --role-sell-vaihto:     #8a5b28;
  --role-sell-ilmaiseksi: #c2a479;
  --role-both-raha:       #1f7a52;
  --role-both-vaihto:     #3e705c;
  --role-both-ilmaiseksi: #7fae9a;

  --pad: 1rem;
  --radius: 4px;
  --focus-ring: 2px solid var(--accent);
  --focus-offset: 2px;

  --dur: 120ms;
  --ease: cubic-bezier(.2,.7,.3,1);
}

@supports (color: oklch(55% 0.1 250)) {
  :root {
    --bg:        oklch(98.7% 0.003 250);
    --bg-sunk:   oklch(95.5% 0.005 250);
    --bg-raise:  oklch(100% 0 0);
    --ink:       oklch(22% 0.015 260);
    --ink-soft:  oklch(47% 0.015 260);
    --rule:      oklch(88% 0.008 260);
    --accent:    oklch(48% 0.10 250);
    --role-buy-raha:        oklch(50% 0.12 250);
    --role-buy-vaihto:      oklch(45% 0.08 250);
    --role-buy-ilmaiseksi:  oklch(65% 0.05 250);
    --role-sell-raha:       oklch(55% 0.13 55);
    --role-sell-vaihto:     oklch(50% 0.09 55);
    --role-sell-ilmaiseksi: oklch(70% 0.06 55);
    --role-both-raha:       oklch(52% 0.12 155);
    --role-both-vaihto:     oklch(48% 0.08 155);
    --role-both-ilmaiseksi: oklch(68% 0.05 155);
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #121419;
    --bg-sunk:   #191c22;
    --bg-raise:  #1e2229;
    --ink:       #e7e9ee;
    --ink-soft:  #a2a7b3;
    --rule:      #2e323b;
    --accent:    #7aa0e8;
    --accent-ink:#0b0f17;
    --role-buy-raha:        #8fb1ee;
    --role-buy-vaihto:      #93a7cf;
    --role-buy-ilmaiseksi:  #b9c5e4;
    --role-sell-raha:       #f0a758;
    --role-sell-vaihto:     #d9a173;
    --role-sell-ilmaiseksi: #e7c69b;
    --role-both-raha:       #65c895;
    --role-both-vaihto:     #80b89e;
    --role-both-ilmaiseksi: #a9d3bd;
  }
  @supports (color: oklch(55% 0.1 250)) {
    :root {
      --bg:        oklch(17% 0.012 250);
      --bg-sunk:   oklch(22% 0.012 250);
      --bg-raise:  oklch(26% 0.012 250);
      --ink:       oklch(93% 0.01 250);
      --ink-soft:  oklch(70% 0.02 250);
      --rule:      oklch(35% 0.012 250);
      --accent:    oklch(72% 0.10 250);
      --role-buy-raha:        oklch(75% 0.11 250);
      --role-buy-vaihto:      oklch(70% 0.07 250);
      --role-buy-ilmaiseksi:  oklch(82% 0.04 250);
      --role-sell-raha:       oklch(75% 0.13 55);
      --role-sell-vaihto:     oklch(70% 0.09 55);
      --role-sell-ilmaiseksi: oklch(82% 0.06 55);
      --role-both-raha:       oklch(72% 0.12 155);
      --role-both-vaihto:     oklch(68% 0.08 155);
      --role-both-ilmaiseksi: oklch(80% 0.05 155);
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  :root { --dur: 0ms; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ============================================================== */
/*  Reset-ish                                                      */
/* ============================================================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Atkinson Hyperlegible", Verdana, "DejaVu Sans", "Bitstream Vera Sans", sans-serif;
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
  -webkit-font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-wrap: break-word;
  word-wrap: break-word;
}
h1, h2, h3 { line-height: var(--lh-tight); margin: 0 0 0.5em; font-weight: 700; }
p { margin: 0 0 0.75em; max-width: var(--measure); }
button, input, textarea, select { font: inherit; color: inherit; }
textarea { font-family: inherit; }
a { color: var(--accent); text-underline-offset: 2px; }

:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}
:focus:not(:focus-visible) { outline: none; }

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

.noscript-notice {
  padding: 1em; margin: 1em auto; max-width: var(--measure);
  border: 1px solid var(--rule); background: var(--bg-raise);
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: clamp(1rem, 3vw, 2rem);
}
.screen {
  max-width: 72rem;
  margin: 0 auto;
  width: 100%;
  padding: clamp(0.75rem, 2vw, 1.5rem);
}
.screen--center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.screen--full {
  max-width: 100%;
  padding: 0;
  flex: 1;
  display: flex;
}
.screen__title {
  font-size: var(--fs-lg);
  margin-bottom: 0.5em;
}
.screen__sub {
  color: var(--ink-soft);
  font-size: var(--fs-sm);
  margin-bottom: 1em;
}
.screen__actions {
  margin-top: 1.25em;
  display: flex;
  justify-content: flex-end;
}

.tiles {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
}
.tile {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--rule);
  background: var(--bg-raise);
  color: inherit;
  padding: 1rem 0.875rem;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  min-height: 7rem;
  text-align: center;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
  min-width: 0;
}
.tile:hover { border-color: var(--ink-soft); }
.tile[aria-selected="true"] {
  border-color: var(--accent);
  background: var(--bg-raise);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.tile__icon { width: 2rem; height: 2rem; color: var(--ink); flex: 0 0 auto; }
.tile__label { font-size: var(--fs-base); overflow-wrap: anywhere; }
.tile__label b { font-weight: 700; }

.ryhmat {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 0.5rem;
}
.ryhma {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--rule);
  background: var(--bg-raise);
  color: inherit;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  text-align: left;
  min-width: 0;
  min-height: 2.75rem;
}
.ryhma:hover { border-color: var(--ink-soft); }
.ryhma[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.ryhma__icon { width: 1.25rem; height: 1.25rem; flex: 0 0 auto; color: var(--ink); }
.ryhma__label {
  font-size: var(--fs-sm);
  line-height: 1.25;
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
  min-width: 0;
}

.input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--bg-raise);
}
.input--large { font-size: var(--fs-md); padding: 0.7rem 0.9rem; }
.form-row { display: flex; gap: 0.5rem; max-width: 32rem; flex-wrap: wrap; }
.form-row .input { flex: 1 1 12rem; }

.button {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--rule);
  background: var(--bg-raise);
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 2.25rem;
}
.button:hover { border-color: var(--ink-soft); }
.button:disabled { opacity: 0.5; cursor: not-allowed; }
.button--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.button--primary:hover { filter: brightness(1.06); }
.button--ghost { background: transparent; }

.inline-skip {
  background: none; border: 0; color: var(--ink-soft);
  text-decoration: underline; cursor: pointer; padding: 0.25rem;
}

.loader__text { font-size: var(--fs-md); color: var(--ink-soft); }

.chat {
  flex: 1;
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr) 14rem;
  min-height: 100vh;
}
@media (max-width: 62em) {
  .chat { grid-template-columns: minmax(0, 1fr); }
  .chat__left, .chat__right { display: none; }
  .chat__left.is-open, .chat__right.is-open {
    display: block;
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 20;
    width: min(85vw, 18rem);
    background: var(--bg-sunk);
    border-right: 1px solid var(--rule);
    overflow-y: auto;
  }
  .chat__right.is-open { left: auto; right: 0; border-right: 0; border-left: 1px solid var(--rule); }
}

.chat__left {
  border-right: 1px solid var(--rule);
  padding: 1rem 0.75rem;
  background: var(--bg-sunk);
  overflow-y: auto;
}
.chat__section-title {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  margin: 0.75rem 0.25rem 0.375rem;
}
.chat__section-title:first-child { margin-top: 0; }

.chat__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.125rem; }
.chat__list button {
  width: 100%;
  text-align: left;
  appearance: none; -webkit-appearance: none;
  border: 0; background: transparent; color: inherit;
  padding: 0.4rem 0.5rem; border-radius: var(--radius); cursor: pointer;
  display: flex; align-items: center; gap: 0.5rem;
  min-width: 0;
}
.chat__list button > span.label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat__list button[aria-current="true"] { background: var(--bg-raise); font-weight: 700; }
.chat__list .unread::after {
  content: " •";
  color: var(--accent);
}
.chat__list-add {
  margin-top: 0.5rem;
  appearance: none; -webkit-appearance: none;
  border: 1px dashed var(--rule); background: transparent;
  color: var(--ink-soft); padding: 0.4rem 0.5rem;
  border-radius: var(--radius); cursor: pointer; width: 100%;
}

.chat__main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
  min-width: 0;
}
.chat__header {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.chat__hamburger {
  display: none;
  appearance: none; -webkit-appearance: none;
  border: 1px solid var(--rule); background: var(--bg-raise);
  color: inherit; cursor: pointer;
  width: 2rem; height: 2rem; border-radius: var(--radius);
  padding: 0;
}
@media (max-width: 62em) {
  .chat__hamburger { display: inline-flex; align-items: center; justify-content: center; }
}
.chat__title { font-size: var(--fs-md); margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1 1 auto; }
#open-right { margin-left: auto; }

.chat__log {
  list-style: none; margin: 0; padding: 0.75rem 1rem;
  background: var(--bg-sunk);
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 0.2rem;
}
.chat__log li {
  display: grid;
  grid-template-columns: 5ch minmax(0, auto) minmax(0, 1fr);
  gap: 0.625rem;
  align-items: baseline;
  max-width: var(--measure);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.chat__log time {
  font-family: "JetBrains Mono", "DejaVu Sans Mono", Consolas, monospace;
  font-size: var(--fs-xs); color: var(--ink-soft);
}
.chat__nick { font-weight: 700; }
.chat__log li.meta {
  color: var(--ink-soft);
  font-style: italic;
  grid-template-columns: 5ch minmax(0, 1fr);
}

.role-buy-raha         { color: var(--role-buy-raha); }
.role-buy-vaihto       { color: var(--role-buy-vaihto); }
.role-buy-ilmaiseksi   { color: var(--role-buy-ilmaiseksi); }
.role-sell-raha        { color: var(--role-sell-raha); }
.role-sell-vaihto      { color: var(--role-sell-vaihto); }
.role-sell-ilmaiseksi  { color: var(--role-sell-ilmaiseksi); }
.role-both-raha        { color: var(--role-both-raha); }
.role-both-vaihto      { color: var(--role-both-vaihto); }
.role-both-ilmaiseksi  { color: var(--role-both-ilmaiseksi); }

.chat__input {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--rule);
  background: var(--bg);
  align-items: end;
}
.chat__image-btn {
  padding: 0.5rem 0.65rem;
  font-size: 1.1rem;
  line-height: 1;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  cursor: pointer;
}
.chat__image-btn:hover { background: var(--bg-raise); }
.chat__image { max-width: 100%; max-height: 20rem; border-radius: var(--radius); display: block; margin-top: 0.25rem; }
.log__entry--image { flex-direction: column; align-items: flex-start; }
.chat__input textarea {
  resize: none;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--bg-raise);
  color: inherit;
  line-height: 1.4;
  min-height: 2.25rem;
  max-height: 8rem;
  width: 100%;
}

.chat__right {
  border-left: 1px solid var(--rule);
  padding: 1rem 0.75rem;
  background: var(--bg-sunk);
  overflow-y: auto;
}

.modal-backdrop {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(10,14,22,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 40;
  padding: 1rem;
}
.modal {
  background: var(--bg-raise);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  max-width: 28rem;
  width: 100%;
}
.modal h2 { font-size: var(--fs-md); margin-bottom: 0.5em; }
.modal__actions {
  display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; flex-wrap: wrap;
}

.toast {
  position: fixed;
  left: 50%; bottom: 1rem;
  transform: translateX(-50%);
  background: var(--bg-raise);
  border: 1px solid var(--rule);
  border-left: 4px solid var(--accent);
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius);
  max-width: calc(100vw - 2rem);
  width: min(40rem, 100%);
  z-index: 50;
}
.toast[data-level="warn"] { border-left-color: var(--warn); }

@media print {
  body { background: white; color: black; }
  .chat__input, .chat__right, .chat__left, .chat__hamburger { display: none; }
  .chat { grid-template-columns: 1fr; }
  .chat__log { background: white; }
  a[href]::after { content: ""; }
}