@font-face {
  font-family: "vv";
  src: local("Tahoma"), local("Verdana"), local("DejaVu Sans"), local("Arial");
  unicode-range: U+0400-04FF;
}

:root {
  --bg: #fdeef2;
  --dot: #f6cbd9;
  --paper: #fff8f4;
  --ink: #4a3640;
  --muted: #7a6470;
  --line: #e7a9bc;
  --accent: #c2527a;
  --sky: #9fc7d9;
  --mark: #fff0b8;
  --field: #fff;
  --counter-bg: #3a2e35;
  --counter-ink: #ffd1e0;
  --av-bg: 86%;
  --av-ink: 32%;
  --edge: dashed;
  --radius: 6px;
  --font: "vv", "MS PGothic", "Hiragino Kaku Gothic ProN", "Osaka", "DejaVu Sans Mono", monospace;
}

:root[data-theme="matcha"] {
  --bg: #eef3e6; --dot: #d3e0c3; --paper: #fafcf4; --ink: #36402f; --muted: #66705e;
  --line: #a9c08f; --accent: #5f7f3f; --sky: #8fb8c4; --mark: #f3efb0;
  --counter-bg: #2f3a29; --counter-ink: #dcefc6;
}
:root[data-theme="sumi"] {
  --bg: #ecebe8; --dot: #dad8d3; --paper: #f8f7f4; --ink: #2b2b2e; --muted: #67676d;
  --line: #b5b2ab; --accent: #8a3a3a; --sky: #8da0ad; --mark: #e8e2c8;
  --counter-bg: #2b2b2e; --counter-ink: #e8e2c8;
  --edge: solid; --radius: 2px;
}
:root[data-theme="night"] {
  color-scheme: dark;
  --av-bg: 30%; --av-ink: 88%;
  --bg: #1c1824; --dot: #2a2535; --paper: #26212f; --ink: #e6dce6; --muted: #a99bac;
  --line: #5a4a68; --accent: #f2a0c0; --sky: #7fb0c8; --mark: #4a3d5c;
  --field: #1f1b27; --counter-bg: #100d15; --counter-ink: #ffc0d8;
}

[hidden] { display: none !important; }
* { box-sizing: border-box; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1.5px, transparent 1.6px);
  background-size: 14px 14px;
  color: var(--ink);
  font: 14px/1.6 var(--font);
  letter-spacing: 0.04em;
}

.box {
  background: var(--paper);
  border: 2px var(--edge) var(--line);
  border-radius: var(--radius);
  box-shadow: 3px 3px 0 var(--dot);
  padding: 10px;
  min-height: 0;
}

h1, h2 { margin: 0 0 6px; font-size: 14px; font-weight: normal; color: var(--accent); }
h1 { font-size: 18px; }

button {
  font: inherit;
  letter-spacing: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: 4px;
  box-shadow: 2px 2px 0 var(--line);
  padding: 1px 8px;
  cursor: pointer;
}
button:active { transform: translate(2px, 2px); box-shadow: none; }

input, textarea {
  font: inherit;
  letter-spacing: inherit;
  color: inherit;
  background: var(--field);
  border: 2px solid var(--line);
  border-radius: 4px;
  padding: 3px 6px;
  min-width: 0;
}
:focus-visible { outline: 2px solid var(--sky); outline-offset: 1px; }

#loginForm { width: min(320px, 90vw); margin: 12vh auto 0; display: grid; gap: 8px; text-align: center; }
#loginErr { margin: 0; min-height: 1.6em; color: var(--accent); }

#app {
  display: grid;
  grid-template-columns: 56px 190px 1fr;
  grid-template-rows: minmax(0, 1fr);
  gap: 12px;
  height: 100vh;
  padding: 12px;
}
#app.p { grid-template-columns: 56px 190px 1fr 380px; }

#rail { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 8px 6px; overflow: auto; min-height: 0; }
#rail button { width: 40px; height: 40px; padding: 0; flex: none; border-radius: 12px; box-shadow: none; font-size: 16px; }
#rail button.on { background: var(--mark); border-color: var(--accent); }
#rail button.add { border-style: dashed; color: var(--muted); }
#srvForm { display: flex; gap: 4px; }
#srvUrl { flex: 1; width: 100%; }
.head { display: block; width: 100%; margin: 0 0 6px; padding: 2px 0; text-align: left; background: none; border: 0; box-shadow: none; font-size: 1.15em; color: var(--accent); font-weight: bold; }
.head small { color: var(--muted); font-weight: normal; }
dialog { padding: 0; width: min(560px, 94vw); color: var(--ink); background: var(--paper); border: 2px var(--edge) var(--line); border-radius: var(--radius); box-shadow: 5px 5px 0 var(--dot); font: inherit; }
dialog::backdrop { background: rgb(60 30 45 / .35); }
dialog .x { position: absolute; top: 8px; right: 8px; margin: 0; }
dialog .x button { padding: 0 8px; }
.dlg { display: grid; grid-template-columns: 140px 1fr; gap: 16px; padding: 18px; min-height: 240px; }
.dlg.one { grid-template-columns: 1fr; align-content: start; gap: 8px; min-height: 0; }
.dlg h2 { margin: 0 0 8px; color: var(--accent); font-size: 1.1em; }
.tabs { display: grid; align-content: start; gap: 4px; padding-right: 12px; border-right: 1px dotted var(--line); }
.tabs button { text-align: left; background: none; border: 0; border-left: 3px solid transparent; border-radius: 2px; box-shadow: none; padding: 4px 8px; }
.tabs button[aria-selected="true"] { background: var(--mark); border-left-color: var(--accent); }
dialog section { display: grid; align-content: start; gap: 8px; min-width: 0; }
dialog section[hidden] { display: none; }
dialog form { display: grid; gap: 6px; }
.opts label { display: block; margin: 4px 0; }
.opts select { max-width: 100%; }
.hint { margin: 0; color: var(--muted); font-size: 12px; }
dialog .msg { margin: 0; padding: 0 18px 12px; min-height: 1.6em; color: var(--accent); font-size: 12px; }
.dlg.one + .msg, .dlg.one .msg { padding: 0; }
.quiet { background: none; border: 0; box-shadow: none; color: var(--muted); font-size: 12px; padding: 2px; text-align: left; }
.empty { margin: 24px; color: var(--muted); text-align: center; }

#side { display: flex; flex-direction: column; gap: 6px; min-height: 0; }
#side h1 { margin: 0 0 6px; }
#side h2 { margin: 6px 0 0; font-size: 12px; color: var(--muted); }
#rooms { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; overflow: auto; min-height: 0; }
#rooms li { display: flex; gap: 2px; }
#rooms button { width: 100%; text-align: left; background: none; border: 0; border-left: 3px solid transparent; border-radius: 2px; box-shadow: none; padding: 3px 8px; }
#rooms button:hover { background: var(--dot); }
#rooms button.on { background: var(--mark); border-left-color: var(--accent); }
#rooms li button:first-child { flex: 1; min-width: 0; }
#rooms button.x { width: auto; flex: none; padding: 0 6px; text-align: center; color: var(--muted); }
.sech { display: flex; align-items: center; justify-content: space-between; }
#side .sech h2 { margin: 6px 0 0; }
.sech .quiet { font-size: 16px; line-height: 1; padding: 0 6px; }
#me { margin-top: auto; display: grid; gap: 8px; padding-top: 8px; border-top: 1px dotted var(--line); }
#meBtn { width: 100%; }
.themes { display: flex; gap: 10px; justify-content: center; }
.themes button { width: 32px; height: 32px; padding: 0; border-radius: 50%; box-shadow: none; }
.themes button[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 2px; }
[data-t="sakura"] { background: #f6b9cd; }
[data-t="matcha"] { background: #b5cf97; }
[data-t="sumi"] { background: #c9c6bf; }
[data-t="night"] { background: #2a2535; }
#offline { padding: 4px 10px; text-align: center; font-size: 12px; background: var(--mark); color: var(--accent); border-bottom: 1px dotted var(--line); }
#status { margin: 0; color: var(--muted); font-size: 12px; min-height: 1.6em; text-align: center; }

main { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
#chatHead { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding-bottom: 8px; border-bottom: 1px dotted var(--line); }
#roomName { flex: 1; margin: 0; min-width: 0; font-size: 16px; }
#voiceBar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; position: relative; }
#voicePing { color: var(--muted); font-size: 12px; }
#voiceWho { flex-basis: 100%; color: var(--muted); font-size: 12px; }
#voiceWho:empty { display: none; }
.say { color: var(--accent); text-decoration: underline; }
select { font: inherit; max-width: 100%; color: inherit; background: var(--field); border: 2px solid var(--line); border-radius: 4px; }

#stage { flex: 0 1 62%; min-height: 120px; display: flex; flex-direction: column; gap: 4px; }
#stage[hidden] { display: none; }
#stage header { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; }
#stage header button { padding: 0 8px; }
#screenVid { flex: 1; min-height: 0; width: 100%; background: #000; border: 2px solid var(--line); border-radius: 4px; object-fit: contain; }
#stage header { gap: 8px; }
#stageSpacer { flex: 1; }
#statPop { position: absolute; top: 100%; left: 0; z-index: 5; margin: 4px 0 0; padding: 8px 10px; max-width: 90vw; white-space: pre-wrap; font: inherit; font-size: 12px; color: var(--text, inherit); background: var(--field); border: 2px solid var(--line); border-radius: 4px; }
#statPop[hidden] { display: none; }
#voiceBar .ic { display: inline-flex; align-items: center; gap: 6px; min-width: 34px; height: 30px; padding: 0 8px; justify-content: center; }
#voiceBar .ic svg { flex: none; }
#voiceBar .ic.on { background: var(--mark); border-color: var(--accent); color: var(--accent); }
#voiceBar .ic.hang svg { transform: rotate(135deg); }
#voiceBar .ic.hang { color: var(--accent); }
.field { display: grid; gap: 4px; }
#codecDiag { margin: 0; white-space: pre-wrap; font: inherit; }
#voiceWho .watch { margin-left: 4px; padding: 0 6px; font-size: 11px; }
#logWrap { position: relative; flex: 1; min-height: 0; display: flex; }
#log { position: relative; flex: 1; min-height: 0; overflow: auto; padding: 2px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
#jump { position: absolute; right: 14px; bottom: 10px; background: var(--paper); }
.day { display: flex; align-items: center; gap: 8px; margin: 12px 0 4px; color: var(--muted); font-size: 11px; }
.day::before, .day::after { content: ""; flex: 1; border-top: 1px dotted var(--line); }
.m { position: relative; display: grid; grid-template-columns: 32px 1fr; gap: 0 10px; margin-top: 8px; padding: 2px 6px; border-radius: 4px; }
.m.cont { margin-top: 0; padding-top: 0; }
.m:hover { background: var(--dot); }
.av, .gut { grid-column: 1; grid-row: 1; }
.body { grid-column: 2; grid-row: 1; min-width: 0; }
.av { width: 32px; height: 32px; padding: 0; border-radius: 50%; box-shadow: none; border: 2px solid var(--line); background: hsl(var(--h) 55% var(--av-bg)); color: hsl(var(--h) 35% var(--av-ink)); font-weight: bold; text-transform: uppercase; line-height: 1; }
.av:active { transform: none; }
.av { position: relative; overflow: hidden; display: inline-block; text-align: center; }
.av img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#pAv { flex: none; width: 28px; height: 28px; line-height: 24px; font-size: 13px; }
#banner { flex: none; height: 64px; margin: -2px -2px 4px; border-radius: 4px; background: var(--mark) center / cover no-repeat; border: 1px solid var(--line); }
#srvBtn { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
#rail button { overflow: hidden; }
#rail button img { width: 100%; height: 100%; object-fit: cover; display: block; }
#brandBox { display: grid; gap: 8px; padding-top: 8px; border-top: 1px dotted var(--line); }
#brandBox h3 { margin: 0; font-size: 13px; color: var(--muted); }
#brandBox .row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.th .av2 { top: auto; bottom: -7px; right: -7px; }
.gut { align-self: start; text-align: center; color: var(--muted); font-size: 10px; opacity: 0; }
.m:hover .gut { opacity: 1; }
.m:not(.cont) .gut, .cont .av, .cont .head { display: none; }
.head { display: flex; align-items: baseline; gap: 8px; }
.head time, .gb time { color: var(--muted); font-size: 11px; }
.m.hl { background: var(--mark); }
.quote { display: block; max-width: 100%; margin: 1px 0 2px; padding: 0 0 0 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; color: var(--muted); font-size: 12px; background: none; border: 0; border-left: 2px solid var(--line); border-radius: 0; box-shadow: none; }
.quote:active { transform: none; }
.pic { display: block; max-width: min(100%, 320px); max-height: 220px; margin-top: 4px; border: 2px solid var(--line); border-radius: 4px; cursor: zoom-in; }
.pic.big { max-width: 100%; max-height: none; cursor: zoom-out; }
.res { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip { padding: 0 7px; border: 1px solid var(--line); border-radius: 10px; box-shadow: none; font-size: 12px; }
.chip:active { transform: none; }
.chip.mine { background: var(--mark); border-color: var(--accent); }
.acts { position: absolute; top: -12px; right: 8px; z-index: 1; display: none; gap: 2px; padding: 1px 3px; background: var(--paper); border: 1px solid var(--line); border-radius: 4px; }
.m:hover .acts, .m:focus-within .acts { display: flex; }
.acts button { padding: 0 5px; border: 0; background: none; box-shadow: none; }
.acts button:active { transform: none; }
.picker { position: absolute; top: 100%; right: 0; display: flex; gap: 2px; margin-top: 2px; padding: 2px 4px; background: var(--paper); border: 1px solid var(--line); border-radius: 4px; box-shadow: 2px 2px 0 var(--dot); }
#rooms button.new { font-weight: bold; }
#replyBar { display: flex; align-items: center; gap: 6px; padding: 2px 8px; border-left: 3px solid var(--accent); background: var(--dot); color: var(--muted); font-size: 12px; }
#replyBar[hidden] { display: none; }
#replyTxt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#replyBar button { padding: 0 6px; }
.txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.txt a { color: var(--accent); }
.nick { border: 0; box-shadow: none; background: none; padding: 0; color: var(--accent); font-weight: bold; }
.nick:hover { text-decoration: underline; }
.nick:active { transform: none; }
#sendForm, #gbForm { display: flex; gap: 6px; align-items: flex-end; }
#text { flex: 1; resize: none; max-height: 120px; line-height: 1.5; overflow-y: hidden; }
#gbText { flex: 1; }

#prof { display: flex; flex-direction: column; gap: 8px; overflow: auto; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
#prof header { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.nw { white-space: nowrap; }
#pName { flex: 1; min-width: 0; color: var(--accent); font-size: 15px; font-weight: bold; }
.counter { background: var(--counter-bg); color: var(--counter-ink); padding: 0 6px; letter-spacing: 2px; font-family: monospace; }
#frame { flex: none; width: 100%; height: 45vh; border: 2px dotted var(--line); background: #fff; }
#src { width: 100%; height: 30vh; font-family: monospace; font-size: 12px; letter-spacing: 0; }
#imgs { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.th, .bw { position: relative; }
.th.mine img { outline: 2px solid var(--accent); outline-offset: 1px; }
.th .star { right: auto; left: -7px; }
#pBtn:empty { display: none; }
.sec { padding-top: 8px; border-top: 1px dotted var(--line); }
#ringBox { display: grid; gap: 6px; }
#ringBox h2 { margin: 0; }
.ring { display: flex; align-items: center; gap: 4px; }
.ring span { flex: 1; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ring button { padding: 0 8px; }
#ringForm { display: flex; gap: 6px; }
#ringName { flex: 1; }
#wall { display: flex; flex-wrap: wrap; gap: 8px; }
.b31 { display: block; width: 88px; height: 31px; padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 0; box-shadow: none; background: var(--mark); font-size: 11px; line-height: 29px; text-align: center; white-space: nowrap; text-overflow: ellipsis; }
.b31 img { display: block; width: 88px; height: 31px; object-fit: cover; }
span.b31 { cursor: default; }
.bw .x { position: absolute; top: -7px; right: -7px; padding: 0 4px; font-size: 11px; line-height: 14px; }
.th img { display: block; height: 48px; max-width: 96px; object-fit: cover; border: 2px solid var(--line); cursor: pointer; }
.th button { position: absolute; top: -7px; right: -7px; padding: 0 4px; font-size: 11px; line-height: 14px; }
#editor p { margin: 4px 0; color: var(--muted); font-size: 12px; }
#book { display: grid; gap: 6px; }
.gb { padding-bottom: 4px; border-bottom: 1px dotted var(--line); }
.gb p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

@media (max-width: 800px) {
  #app, #app.p { grid-template-columns: 1fr; grid-template-rows: auto auto minmax(0, 1fr); }
  #rail { flex-direction: row; padding: 6px 10px; }
  #rail button { width: 34px; height: 34px; }
  #side { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 6px 10px; }
  #side h1 { margin: 0; font-size: 15px; }
  #side h2 { display: none; }
  #rooms { display: flex; margin: 0; }
  #rooms button { width: auto; }
  #me { margin: 0 0 0 auto; display: flex; align-items: center; padding: 0; border: 0; }
  #meBtn { width: auto; }
  #status { display: none; }
  .dlg { grid-template-columns: 1fr; }
  .tabs { display: flex; padding: 0 0 8px; border: 0; border-bottom: 1px dotted var(--line); }
  #prof { position: fixed; inset: 8px; z-index: 1; }
}
#rooms button.at { color: var(--accent); font-weight: bold; }
.m.at { background: var(--mark); box-shadow: inset 3px 0 0 var(--accent); }
