/* The Studio: warm paper, wood and leaf; clean, no kitsch. */
:root {
  --paper: #fbf6ec;
  --card: #fffdf8;
  --ink: #3b2a1e;
  --muted: #8a7563;
  --line: #e7dccb;
  --wood: #9a5f34;
  --wood-dark: #74452a;
  --leaf: #5c8f3c;
  --leaf-soft: #e6f0d8;
  --sky: #dcecf3;
  --warn: #b5482f;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(59, 42, 30, .06), 0 4px 14px rgba(59, 42, 30, .06);
  --checker: repeating-conic-gradient(#efe6d6 0 25%, #f8f2e6 0 50%) 0 0 / 16px 16px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.45 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--wood); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.error { color: var(--warn); min-height: 1.2em; margin: .4em 0 0; }
canvas.pix, img.pix { image-rendering: pixelated; image-rendering: crisp-edges; }
[hidden] { display: none !important; }

/* Buttons and inputs */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: .5em 1.05em; font: inherit; font-weight: 600; cursor: pointer;
  min-height: 40px; display: inline-flex; align-items: center; gap: .4em; text-decoration: none;
  touch-action: manipulation;
}
.btn:hover { border-color: #d5c4ab; background: #fff; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--leaf); border-color: var(--leaf); color: #fff; }
.btn.primary:hover { background: #4f7f32; }
.btn.wood { background: var(--wood); border-color: var(--wood); color: #fff; }
.btn.small { min-height: 32px; padding: .3em .8em; font-size: .9em; }
.btn.ghost { background: transparent; border-color: transparent; }
input, select, textarea {
  font: inherit; color: inherit; background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: .5em .7em; min-height: 40px; width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid #c9a46f; outline-offset: 1px; }
label { display: block; font-weight: 600; font-size: .9rem; margin: 0 0 .8em; }
label > input, label > select, label > textarea { margin-top: .3em; font-weight: 400; }
.check { display: flex; align-items: center; gap: .5em; font-weight: 600; }
.check input { width: auto; min-height: 0; }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 500px at 50% -10%, var(--sky), transparent 70%), var(--paper); }
.login-card { width: min(380px, 100%); background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px; box-shadow: var(--shadow); }
.login-card form { margin-top: 18px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 4px; }

.brand { display: flex; align-items: center; gap: .5em; font-weight: 800; letter-spacing: .01em; color: var(--wood-dark); text-decoration: none; }
.brand img { image-rendering: pixelated; }
.brand.big { font-size: 1.6rem; }

/* App shell */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; background: rgba(251, 246, 236, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.top .spacer { flex: 1; }
.top .who { color: var(--muted); font-size: .9rem; }
main.page { max-width: 1280px; margin: 0 auto; padding: 20px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: .6em 1.1em; border-radius: 999px; box-shadow: var(--shadow); z-index: 50; max-width: calc(100vw - 32px); }
.toast.bad { background: var(--warn); }

/* Gallery */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar input[type=search] { flex: 1 1 220px; max-width: 360px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: .25em .8em;
  font-size: .9rem; cursor: pointer; min-height: 32px; font: inherit; color: inherit; }
.chip.on { background: var(--leaf-soft); border-color: #bcd3a2; color: #35561f; font-weight: 600; }
.group { margin: 22px 0 8px; display: flex; align-items: baseline; gap: 10px; }
.group h2 { margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; display: flex; flex-direction: column; text-decoration: none; color: inherit; transition: transform .12s;
}
.card:hover { transform: translateY(-2px); }
.card .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); }
.card .pair.single { grid-template-columns: 1fr; }
.card .thumb { background: var(--checker); height: 150px; display: grid; place-items: center; position: relative; overflow: hidden; padding: 6px; }
.card .thumb canvas { max-width: 100%; max-height: 100%; }
.card .thumb .lbl { position: absolute; left: 6px; top: 6px; font-size: .7rem; background: rgba(255,253,248,.9);
  border-radius: 6px; padding: 0 .4em; color: var(--muted); }
.card .thumb .empty { color: var(--muted); font-size: .85rem; }
.card .body { padding: 10px 12px 12px; }
.card .name { font-weight: 700; }
.card .meta { font-size: .8rem; color: var(--muted); }
.tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.tag { font-size: .75rem; background: #f3eadb; border-radius: 6px; padding: 0 .45em; color: #6b5543; }
.badge { font-size: .72rem; background: var(--leaf-soft); color: #35561f; border-radius: 6px; padding: .05em .45em; font-weight: 700; }
.emptystate { text-align: center; padding: 60px 20px; color: var(--muted); }

/* Dialog */
dialog { border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: min(440px, calc(100vw - 32px));
  background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(59,42,30,.25); }
dialog::backdrop { background: rgba(59, 42, 30, .35); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }

/* Asset page */
.asset-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 12px; }
.asset-head h1 { margin: 0; }
.asset-head .spacer { flex: 1; }
.crumbs { font-size: .9rem; color: var(--muted); margin-bottom: 6px; }
.crumbs a { text-decoration: none; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tab { border: 0; background: none; font: inherit; color: var(--muted); padding: .6em .9em; cursor: pointer;
  border-bottom: 3px solid transparent; min-height: 44px; display: flex; align-items: center; gap: .4em; }
.tab.on { color: var(--ink); border-bottom-color: var(--wood); font-weight: 700; }
.tab .dot { width: 8px; height: 8px; border-radius: 50%; background: #d8ccb9; }
.tab .dot.drawn { background: var(--leaf); }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 14px; }
.panel h3 { display: flex; align-items: center; gap: 8px; }
.note { font-size: .85rem; color: var(--muted); background: #f6efe2; border-radius: 8px; padding: .5em .7em; margin: .5em 0; }
.note.port { background: var(--sky); color: #2c5466; }
.editor-host { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); height: min(76vh, 820px); min-height: 420px; overflow: hidden; position: relative; }
.editor-host > .stub { height: 100%; overflow: auto; }
.savebar { display: flex; gap: 8px; align-items: center; margin: 10px 0 14px; flex-wrap: wrap; }
.savebar .state { color: var(--muted); font-size: .9rem; }
.refs { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; }
.ref { position: relative; background: var(--checker); border-radius: 8px; height: 90px; display: grid; place-items: center; overflow: hidden; }
.ref img { max-width: 100%; max-height: 100%; }
.ref button { position: absolute; top: 3px; right: 3px; }
.history { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow: auto; }
.history li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.history li:last-child { border-bottom: 0; }
.history .hthumb { width: 48px; height: 48px; background: var(--checker); border-radius: 6px; display: grid; place-items: center; flex: none; overflow: hidden; }
.history .hthumb img { max-width: 100%; max-height: 100%; }
.history .what { flex: 1; min-width: 0; font-size: .88rem; }
.history .what small { color: var(--muted); display: block; }

/* Preview */
.preview { overflow: hidden; }
.preview .stage { background: #7aa25a; border-radius: 10px; overflow: auto; touch-action: pan-x pan-y; max-height: 70vh; }
.preview .stage.fit canvas { width: 100% !important; height: auto !important; }
.preview canvas { display: block; }
.preview .controls { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; align-items: center; }

/* Editor stub */
.stub { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding: 12px; }
.stub .canvas-wrap { background: var(--checker); border-radius: 8px; overflow: auto; display: grid; place-items: center; min-height: 280px; position: relative; padding: 12px; }
.stub .stack { position: relative; }
.stub .stack canvas { position: absolute; left: 0; top: 0; }
.stub .stack canvas:first-child { position: relative; }
.stub .side { width: 180px; display: flex; flex-direction: column; gap: 8px; }
.stub .side img { width: 100%; border-radius: 6px; background: var(--checker); }
.stub input[type=range] { padding: 0; min-height: 28px; }

@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  main.page { padding: 14px 16px; }
  .top { padding: 8px 16px; }
  .top .who { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .card .thumb { height: 120px; }
  .stub { grid-template-columns: 1fr; }
  .stub .side { width: auto; }
}

/* Palettes */
.palettes { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.palette { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow); }
.pname { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.swatches { display: grid; grid-template-columns: repeat(16, 1fr); gap: 2px; }
.sw { aspect-ratio: 1; border: 0; border-radius: 3px; padding: 0; cursor: pointer; min-width: 0; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }
.sw:hover { transform: scale(1.25); position: relative; z-index: 1; }
.top nav { display: flex; gap: 4px; }
.top nav a { text-decoration: none; color: var(--muted); font-weight: 600; padding: .35em .7em; border-radius: 999px; }
.top nav a.on { color: var(--ink); background: #f1e7d6; }

/* ---- type previews ---- */
.preview h4 { margin: 14px 0 6px; font-size: .9rem; }
.muted.small, .preview .small { font-size: .85rem; margin: .5em 0 0; }
/* Dialogue box mock-up, in the game's parchment and wood colours. */
.dlg { display: flex; gap: 8px; margin: 0 0 12px; padding: 8px; border: 4px solid #b4632b; border-radius: 6px;
  background: #f9d391; box-shadow: inset 0 0 0 2px #e8a85a, 0 2px 0 #74452a; color: #3b1d06; }
.dlg-text { flex: 1; font: 600 1.05rem/1.45 Georgia, 'Times New Roman', serif; padding: 6px 8px; min-height: 128px; }
.dlg-side { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.dlg-portrait { background: #fce3b0; border: 3px solid #b4632b; border-radius: 4px; line-height: 0; }
.dlg-name { background: #fce3b0; border: 3px solid #b4632b; border-radius: 4px; padding: 0 8px; font: 700 .9rem Georgia, serif; }
.sheets { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.sheets figure { margin: 0; background: var(--checker); border: 1px solid var(--line); border-radius: 8px; padding: 6px; text-align: center; }
.sheets img { max-width: 100%; max-height: 220px; image-rendering: pixelated; }
.sheets figcaption { font-size: .75rem; color: var(--muted); margin-top: 4px; }
.sheets .empty { color: var(--muted); font-size: .8rem; padding: 20px 0; }
/* Fields: picking assets (collections), extra fields in the "new" dialog. */
.assetpick { display: grid; gap: 2px; max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: var(--card); }
.assetpick .check { margin: 0; }
div.field { display: grid; gap: 4px; margin: 0 0 12px; }
.create-fields label { display: block; }
/* Gallery: by character. */
.charhead { display: flex; align-items: center; gap: 12px; margin: 22px 0 8px; }
.charhead .faces { display: flex; gap: 6px; align-items: flex-end; }
.charhead canvas { image-rendering: pixelated; background: var(--checker); border-radius: 6px; border: 1px solid var(--line); }
.charhead h2 { margin: 0; }
.mosaic { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; width: 100%; height: 100%; padding: 6px; box-sizing: border-box; }
.mosaic > div { display: flex; align-items: center; justify-content: center; min-height: 0; min-width: 0; overflow: hidden; }
.mosaic canvas { max-width: 100%; max-height: 100%; image-rendering: pixelated; }
.adopt-box { display: flex; gap: 12px; align-items: center; margin-top: 12px; padding: 10px; border: 4px solid #b4632b; border-radius: 6px; background: #f9d391; color: #3b1d06; }
.adopt-box canvas { background: #fce3b0; border: 2px solid #b4632b; border-radius: 4px; padding: 4px; }

/* Delete, undo and the Archive */
.toast.withaction { display: flex; align-items: center; gap: 12px; padding: .4em .5em .4em 1.1em; }
.toast.withaction .btn { background: #fff; color: var(--ink); border-color: #fff; }
.btn.danger { background: var(--warn); border-color: var(--warn); color: #fff; }
dialog.ask .q { font-size: 1.1em; font-weight: 600; margin: 0 0 8px; }
.archive { display: flex; flex-direction: column; gap: 8px; }
.arow { display: flex; align-items: center; gap: 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.arow .what { flex: 1; min-width: 0; }
.arow .what > * { overflow: hidden; text-overflow: ellipsis; }
.athumb { width: 72px; height: 72px; flex: none; display: grid; place-items: center; background: var(--checker); border-radius: 8px; overflow: hidden; }
.athumb img { max-width: 100%; max-height: 100%; image-rendering: pixelated; }
.dangerzone { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); display: flex; flex-wrap: wrap; gap: 8px; }
.savebar .spacer { flex: 1; }
.prevwrap { position: relative; }
.livebadge { position: absolute; top: 14px; right: 14px; z-index: 2; background: #d9573b; color: #fff; border-radius: 999px; padding: .15em .75em; font-size: .8rem; font-weight: 700; box-shadow: var(--shadow); }
.livebadge[hidden] { display: none; }
