:root {
  --bg: #fff8f1; --panel: #ffffff; --ink: #2b2340; --muted: #7c7290; --line: #f0e2d4;
  --accent: #ff8a5b; --accent-ink: #ffffff; --soft: #fff0e5; --me: #ffe3d3; --agent: #f3f0ff;
  --ok: #2e9d6a; --err: #c8402f; --radius: 18px;
  --shadow: 0 6px 24px rgba(80, 40, 20, .08);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1d1a26; --panel: #262233; --ink: #f4efff; --muted: #a89fbb; --line: #383247;
    --soft: #322b40; --me: #4a3327; --agent: #2f2a44; color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.45; }
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
h1 { font-size: 1.15rem; margin: 0; }
h2 { margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--err); min-height: 1.4em; margin: .5rem 0 0; }
.grow { flex: 1; }

button, .btn { border: 0; border-radius: 999px; padding: .55rem 1rem; cursor: pointer; background: var(--soft); text-decoration: none; display: inline-flex; align-items: center; gap: .3rem; }
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.primary:disabled { opacity: .5; cursor: default; }
.ghost { background: transparent; border: 1.5px solid var(--line); }
.ghost:hover, .ghost:focus-visible { border-color: var(--accent); }
.block { width: 100%; justify-content: center; }
.icon { background: transparent; font-size: 1.3rem; padding: .3rem .6rem; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

/* connexion */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); border-radius: 28px; box-shadow: var(--shadow); padding: 2rem; width: min(380px, 100%); display: grid; gap: .9rem; text-align: center; }
.card label { display: grid; gap: .3rem; text-align: left; font-weight: 600; }
.card input { border: 1.5px solid var(--line); border-radius: 14px; padding: .7rem .9rem; background: var(--bg); }
.logo { font-size: 3rem; }

/* atelier */
.app { height: 100%; display: grid; grid-template-columns: 230px minmax(320px, 1fr) minmax(320px, 1.1fr); grid-template-rows: auto 1fr; }
.top { grid-column: 1 / -1; display: flex; align-items: center; gap: .8rem; padding: .6rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line); }
.gametitle { font-weight: 700; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.games { background: var(--panel); border-right: 1px solid var(--line); padding: 1rem; overflow: auto; }
.games ul { list-style: none; padding: 0; margin: 1rem 0 0; display: grid; gap: .3rem; }
.games li button { width: 100%; text-align: left; border-radius: 14px; background: transparent; padding: .6rem .8rem; display: block; }
.games li button small { display: block; color: var(--muted); font-size: .75rem; }
.games li button.on { background: var(--soft); font-weight: 700; }

.chat { position: relative; display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.empty { margin: auto; text-align: center; padding: 2rem; max-width: 420px; color: var(--muted); }
.empty h2 { color: var(--ink); }
.big { font-size: 3.5rem; }
.messages { list-style: none; margin: 0; padding: 1rem; overflow: auto; flex: 1; display: flex; flex-direction: column; gap: .7rem; }
.msg { max-width: 88%; padding: .7rem 1rem; border-radius: var(--radius); white-space: pre-wrap; word-wrap: break-word; }
.msg.me { align-self: flex-end; background: var(--me); border-bottom-right-radius: 6px; }
.msg.agent { align-self: flex-start; background: var(--agent); border-bottom-left-radius: 6px; }
.msg .who { font-size: .75rem; color: var(--muted); display: block; margin-bottom: .2rem; }
.msg .thumbs { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .4rem; }
.msg .thumbs img { height: 72px; border-radius: 10px; background: var(--panel); }
.msg .tools { margin-top: .4rem; font-size: .8rem; color: var(--muted); }
.msg.err { background: color-mix(in srgb, var(--err) 15%, var(--panel)); }
.typing::after { content: "…"; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

.composer { padding: .7rem; border-top: 1px solid var(--line); background: var(--panel); }
.composer .row { display: flex; gap: .5rem; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; border: 1.5px solid var(--line); border-radius: 16px; padding: .65rem .9rem; background: var(--bg); max-height: 40vh; }
.attach { cursor: pointer; font-size: 1.4rem; padding: .4rem; border-radius: 12px; }
.attach:hover { background: var(--soft); }
.pending { display: flex; gap: .5rem; flex-wrap: wrap; }
.pending:not(:empty) { margin-bottom: .5rem; }
.chip { position: relative; background: var(--soft); border-radius: 12px; padding: .3rem; display: flex; align-items: center; gap: .4rem; font-size: .8rem; }
.chip img { height: 48px; border-radius: 8px; }
.chip .x { padding: .1rem .45rem; background: var(--panel); }
.chip.up { opacity: .6; }
.drop { position: absolute; inset: .5rem; border: 3px dashed var(--accent); border-radius: 24px; display: grid; place-items: center; font-size: 1.4rem; font-weight: 700; background: color-mix(in srgb, var(--bg) 85%, transparent); pointer-events: none; }

.play { display: flex; flex-direction: column; min-height: 0; background: var(--soft); }
.playbar { display: flex; gap: .4rem; padding: .5rem .7rem; align-items: center; flex-wrap: wrap; }
.frame { position: relative; flex: 1; min-height: 0; padding: 0 .7rem .7rem; }
.frame iframe { width: 100%; height: 100%; border: 0; border-radius: 22px; background: #fff; box-shadow: var(--shadow); }
.nogame { position: absolute; inset: 0 .7rem .7rem; display: grid; place-items: center; color: var(--muted); border-radius: 22px; border: 2px dashed var(--line); background: var(--panel); }

.sheet { border: 0; border-radius: 24px; padding: 1.4rem; width: min(560px, calc(100% - 32px)); max-height: 80vh; background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.sheet::backdrop { background: rgba(30, 20, 40, .35); }
.sheet .close { float: right; }
.sheet ul { list-style: none; padding: 0; margin: 0; display: grid; gap: .4rem; }
.sheet li { display: flex; align-items: center; gap: .6rem; justify-content: space-between; padding: .5rem .2rem; border-bottom: 1px solid var(--line); }
.sheet li img { height: 44px; border-radius: 8px; }
.grid-assets { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .6rem; }
.grid-assets figure { margin: 0; background: var(--soft); border-radius: 14px; padding: .4rem; text-align: center; font-size: .75rem; overflow-wrap: anywhere; }
.grid-assets img { width: 100%; height: 90px; object-fit: contain; }

.only-narrow { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .only-narrow { display: inline-flex; }
  .top h1 { display: none; }
  .tabs { display: flex; gap: .3rem; }
  .tab { padding: .4rem .8rem; }
  .tab.on { background: var(--accent); color: var(--accent-ink); }
  .games { position: fixed; z-index: 5; top: 0; bottom: 0; left: 0; width: min(300px, 85vw); transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .games.open { transform: none; }
  .chat, .play { grid-column: 1; grid-row: 2; border-right: 0; }
  .app.show-play .chat, .app:not(.show-play) .play { display: none; }
  #spend { display: none; }
  .top { padding: .5rem 16px; }
}
