:root {
  --accent: #1f7a4d;
  --accent-soft: #e8f2ec;
  --bg: #ece9e3;            /* gris càlid editorial */
  --panel: #ffffff;
  --ink: #16140f;          /* quasi negre */
  --muted: #6f695e;
  --line: #d9d4ca;         /* fil fi */
  --user-bubble: var(--accent);
  --serif: 'Fraunces', Georgia, 'Times New Roman', serif;
  --mono: 'Space Mono', ui-monospace, monospace;
  --sans: 'Atkinson Hyperlegible', system-ui, -apple-system, sans-serif;
  --radius: 10px;
}

/* l'atribut hidden ha de guanyar sempre */
[hidden] { display: none !important; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans); background: var(--bg); color: var(--ink);
  font-size: 18px; line-height: 1.5;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--ink); color: #fff; padding: 10px 16px; z-index: 100; }
.skip-link:focus { left: 0; }

/* barra superior */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 18px 26px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 16px; }
.brand-emoji { font-size: 2rem; }
h1 { font-size: 1.7rem; margin: 0; }
.subtitle { margin: 3px 0 0; color: var(--muted); font-size: .9rem; max-width: 56ch; font-family: var(--sans); }

.power { display: flex; align-items: center; gap: 9px; font-family: var(--mono); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #c3beb3; display: inline-block; }
.dot.on { background: #35c46a; } .dot.off { background: #c9c4ba; }
.dot.wake { background: #e0a21a; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* botons */
.btn {
  background: var(--ink); color: #fff; border: 1px solid var(--ink); border-radius: 6px;
  padding: 12px 20px; font-family: var(--mono); font-size: .8rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; cursor: pointer;
}
.btn:hover { background: #000; }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-icon { background: var(--panel); color: var(--ink); border: 1px solid var(--line); padding: 10px 13px; font-size: 1.1rem; }
.btn-icon:hover { background: var(--bg); }
.btn-block { width: 100%; }

/* disposició */
.layout { display: grid; grid-template-columns: 1fr 390px; gap: 22px; padding: 22px; max-width: 1240px; margin: 0 auto; align-items: start; }
@media (max-width: 880px) { .layout { grid-template-columns: 1fr; } }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }

/* xat */
.chat-panel { display: flex; flex-direction: column; min-height: 70vh; }
.messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding: 4px; }
.msg { max-width: 82%; padding: 13px 17px; border-radius: 16px; white-space: pre-wrap; line-height: 1.5; }
.msg.tutor { background: var(--accent-soft); border: 1px solid var(--line); border-bottom-left-radius: 4px; align-self: flex-start; }
.msg.user { background: var(--ink); color: #fff; border-bottom-right-radius: 4px; align-self: flex-end; }
.msg.system { background: #fbf4e3; border: 1px dashed #d8b863; align-self: center; font-size: .92rem; color: #6a5420; }
.msg .who { display: block; font-family: var(--mono); font-size: .64rem; font-weight: 700; opacity: .65; margin-bottom: 5px; text-transform: uppercase; letter-spacing: .08em; }
.typing { font-style: italic; color: var(--muted); }

.composer { display: flex; gap: 10px; margin-top: 14px; }
textarea#chat-input { flex: 1; resize: none; font-family: var(--sans); font-size: 1.05rem; padding: 13px 15px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: #fff; }
textarea#chat-input:focus { outline: none; border-color: var(--accent); }
.hint { color: var(--muted); font-size: .85rem; margin: 10px 2px 0; }

/* simulador */
.sim-panel h2 { margin-top: 0; font-size: 1.2rem; display: flex; align-items: center; gap: 10px; }
.live-badge { font-family: var(--mono); font-size: .6rem; background: var(--ink); color: #fff; padding: 3px 8px; border-radius: 2px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.sim-place { color: var(--muted); margin-top: 0; font-family: var(--mono); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; margin-bottom: 18px; background: var(--line); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.card { background: var(--panel); padding: 12px 14px; }
.card .v { font-size: 1.45rem; font-weight: 600; font-family: var(--serif); color: var(--ink); }
.card .v small { font-size: .8rem; color: var(--muted); }
.card .l { font-family: var(--mono); font-size: .66rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-top: 2px; }
.chart-controls { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-family: var(--mono); font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
select#sensor-select { font-family: var(--sans); font-size: .9rem; padding: 7px 9px; border-radius: 6px; border: 1px solid var(--line); background: #fff; }
.chart-wrap { position: relative; }

/* imatges al xat */
.image-preview { position: relative; display: inline-block; margin-bottom: 10px; }
.image-preview img { max-height: 90px; border-radius: 8px; border: 1px solid var(--line); display: block; }
.image-preview button { position: absolute; top: -8px; right: -8px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: #c0392b; color: #fff; cursor: pointer; font-size: 15px; line-height: 1; }
.msg-img { max-width: 230px; max-height: 230px; border-radius: 8px; margin-bottom: 6px; display: block; }

/* entrada per codi */
.join-wrap { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: var(--bg); }
.join-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 42px 34px; width: 100%; max-width: 420px; text-align: center; display: flex; flex-direction: column; gap: 12px; }
.join-emoji { font-size: 3.2rem; }
.join-card h1 { margin: 0; font-size: 1.9rem; }
.join-card .muted { color: var(--muted); font-size: .95rem; }
.join-card input { padding: 16px; border: 1px solid var(--line); border-radius: 10px; font-family: var(--mono); font-size: 1.5rem; text-align: center; letter-spacing: 6px; text-transform: uppercase; background: #fff; }
.join-card input:focus { outline: none; border-color: var(--accent); }
.join-card .btn { padding: 15px; font-size: .9rem; }
.error { color: #c0392b; min-height: 1.2em; margin: 0; font-family: var(--mono); font-size: .8rem; }
.muted { color: var(--muted); }

/* perfil: text gran (accessibilitat) */
body.big-text { font-size: 22px; }
body.big-text .msg { font-size: 1.08em; }
body.big-text textarea#chat-input { font-size: 1.25rem; }
body.big-text h1 { font-size: 2rem; }
