/*
 * 慕斯小镇 · 3D 地图（BlueMap）—— 在 BlueMap 自带样式上面盖一层，和主站 oldtimes.club、map.oldtimes.club 同一套样子。
 *
 * 配色、按钮、卡片照主站主题 oldtimes-mc 的 mc.css（第 67 节按钮、第 69 节卡片、第 74 节浅色主题）。
 * 主题：
 *   - BlueMap 设置里选「跟随主站」（默认）时，跟着主站的 cookie ot_theme（判定脚本内联在 index.html 的 <head>）。
 *   - 选了浅色 / 深色 / 高对比时照选的来。BlueMap 把主题类名加在 #map-container 上，可界面 #app 不在它里面，
 *     原版的主题设置对界面其实不生效 —— 这里用 html:has(#map-container.theme-xxx) 接上。
 * BlueMap 只在升级时重写网页文件；这个文件由 ~/bluemap-web-custom/apply.py 装进来，也登记在 webapp.conf 的 styles 里。
 */

html {
  --ot-btn-r: 12px;
  --ot-card-r: 18px;
  --ot-green-top: #448c2b;
  --ot-green-bottom: #2a641c;
  --ot-green-edge: #1f4d14;
  --ot-font: "Noto Sans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC",
             "Helvetica Neue", Helvetica, Arial, sans-serif;
  --ot-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

/* 深色（主站默认）。选择器要比 BlueMap 的 :root 重，所以写 html:root / html[data-ot-theme] */
html:root,
html[data-ot-theme],
html:has(#map-container.theme-dark) {
  --ot-table: #201e1c;
  --ot-paper: #3a3734;
  --ot-paper-line: rgba(255, 246, 232, .043);
  --ot-edge: #201e1c;
  --ot-ink: #fcf5f1;
  --ot-ink-mute: #aba09c;
  --ot-btn-top: #4a4643;
  --ot-btn-bottom: #35322f;
  --ot-tag-bg: rgba(108, 195, 73, .18);
  --ot-tag-ink: #86d562;
  --ot-field: #2b2927;
  --ot-drop: 0 16px 32px -14px rgba(0, 0, 0, .6);
  --ot-gloss: inset 0 2px 0 rgba(255, 255, 255, .12);

  --theme-bg: var(--ot-paper);
  --theme-bg-hover: #4a4643;
  --theme-bg-light: #5a5450;
  --theme-fg: var(--ot-ink);
  --theme-fg-light: var(--ot-ink-mute);
  --theme-switch-button-on: var(--ot-green-top);
}

html[data-ot-theme="light"],
html[data-ot-theme]:has(#map-container.theme-light) {
  --ot-table: #e8dfd0;
  --ot-paper: #f7f3ea;
  --ot-paper-line: rgba(87, 70, 50, .06);
  --ot-edge: #b9ab92;
  --ot-ink: #2e2a26;
  --ot-ink-mute: #70675e;
  --ot-btn-top: #fffdf8;
  --ot-btn-bottom: #ece3d4;
  --ot-tag-ink: #2f6b1c;
  --ot-field: #fffdf8;
  --ot-drop: 0 16px 32px -14px rgba(74, 58, 40, .35);
  --ot-gloss: inset 0 2px 0 rgba(255, 255, 255, .85);

  --theme-bg: var(--ot-paper);
  --theme-bg-hover: #ece3d4;
  --theme-bg-light: #cfc2aa;
  --theme-fg: var(--ot-ink);
  --theme-fg-light: var(--ot-ink-mute);
  --theme-switch-button-on: var(--ot-green-top);
}
/* 用户选了深色时，压过主站的浅色 */
html[data-ot-theme="light"]:has(#map-container.theme-dark) {
  --ot-table: #201e1c; --ot-paper: #3a3734; --ot-paper-line: rgba(255, 246, 232, .043); --ot-edge: #201e1c;
  --ot-ink: #fcf5f1; --ot-ink-mute: #aba09c; --ot-btn-top: #4a4643; --ot-btn-bottom: #35322f;
  --ot-tag-ink: #86d562; --ot-field: #2b2927; --ot-drop: 0 16px 32px -14px rgba(0, 0, 0, .6);
  --ot-gloss: inset 0 2px 0 rgba(255, 255, 255, .12);
  --theme-bg: var(--ot-paper); --theme-bg-hover: #4a4643; --theme-bg-light: #5a5450;
  --theme-fg: var(--ot-ink); --theme-fg-light: var(--ot-ink-mute);
}
/* 高对比：保留 BlueMap 原样的黑白 */
html:has(#map-container.theme-contrast) {
  --ot-paper: #000; --ot-paper-line: transparent; --ot-edge: #666; --ot-ink: #fff; --ot-ink-mute: #aaa;
  --ot-btn-top: #000; --ot-btn-bottom: #000; --ot-field: #000; --ot-gloss: none;
  --theme-bg: #000; --theme-bg-hover: #222; --theme-bg-light: #666; --theme-fg: #fff; --theme-fg-light: #aaa;
  --theme-switch-button-on: #006fff;
}

html, html[data-ot-theme] { font-family: var(--ot-font); }
#app { font-family: var(--ot-font); font-weight: 500; }
#app input, #app button, #app select { font-family: var(--ot-font); }

/* ==========================================================================
   糖果按钮：描边用内阴影画（不改尺寸），底下一道 3px 实色边当厚度
   ========================================================================== */
#app .svg-button,
#zoom-buttons .svg-button {
  background-color: transparent;
  background-image: linear-gradient(180deg, var(--ot-btn-top), var(--ot-btn-bottom));
  color: var(--ot-ink);
  transition: background .12s ease-out, transform .12s ease-out;
}
#app .svg-button:hover,
#app .svg-button.active {
  background-image: linear-gradient(180deg, var(--ot-green-top), var(--ot-green-bottom));
  color: #fff;
}
#app .svg-button svg { fill: currentColor; }
#app .svg-button:active { transform: translateY(1px); }

/* ---- 顶部控制条：电脑上按 .space 分成几组，每组是一块糖果 ----
   组的描边画在 ::after 上、叠在最上层：视角那组、坐标那组里面还有子元素，
   描边要是画在自己身上（inset 阴影），会被子元素的底色盖住，上下边就断了。 */
#app .control-bar {
  filter: none;
  height: calc(2em + 4px);
}
#app .control-bar > :not(.space) {
  position: relative;
  overflow: hidden;
  background-color: var(--ot-paper);
  box-shadow: 0 3px 0 var(--ot-edge);
  color: var(--ot-ink);
}
#app .control-bar > :not(.space)::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  border-radius: inherit;
  box-shadow: inset 0 2px 0 var(--ot-edge), inset 0 -2px 0 var(--ot-edge);
}
#app .control-bar .controls-switch > .svg-button,
#app .control-bar .position-input > * { height: 100%; }

@media (min-width: 576px) {
  #app .control-bar { margin: .6em; width: calc(100% - 1.2em); }
  #app .control-bar > .space { width: .6em; }
  /* 一组的头 */
  #app .control-bar > :first-child,
  #app .control-bar > .space + * {
    border-top-left-radius: var(--ot-btn-r);
    border-bottom-left-radius: var(--ot-btn-r);
  }
  #app .control-bar > :first-child::after,
  #app .control-bar > .space + *::after {
    box-shadow: inset 2px 0 0 var(--ot-edge), inset 0 2px 0 var(--ot-edge), inset 0 -2px 0 var(--ot-edge);
  }
  /* 一组的尾 */
  #app .control-bar > :last-child,
  #app .control-bar > :has(+ .space) {
    border-top-right-radius: var(--ot-btn-r);
    border-bottom-right-radius: var(--ot-btn-r);
  }
  #app .control-bar > :last-child::after,
  #app .control-bar > :has(+ .space)::after {
    box-shadow: inset -2px 0 0 var(--ot-edge), inset 0 2px 0 var(--ot-edge), inset 0 -2px 0 var(--ot-edge);
  }
  /* 一组只有一颗：头尾都是它 */
  #app .control-bar > :first-child:has(+ .space)::after,
  #app .control-bar > .space + :has(+ .space)::after,
  #app .control-bar > .space + :last-child::after {
    box-shadow: inset 0 0 0 2px var(--ot-edge);
  }
}

/* 一组就是一整块糖果，组内不要分隔线（BlueMap 原样式给每一项、坐标 x/z 之间都加了左边线） */
#app .control-bar > *,
#app .control-bar > :not(:first-child),
#app .position-input > *,
#app .position-input > :not(:first-child),
#app .controls-switch > * { border-left: none !important; }

/* 坐标框：和按钮同一种底色、同一套字体（原来是平的纸面色加等宽字） */
#app .number-input {
  background-color: transparent;
  background-image: linear-gradient(180deg, var(--ot-btn-top), var(--ot-btn-bottom));
  color: var(--ot-ink);
}
#app .number-input .label {
  color: var(--ot-ink-mute);
  font-weight: 700;
}
#app .number-input input {
  background: transparent;
  color: var(--ot-ink);
  font-family: var(--ot-font);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---- 右下缩放 ---- */
#zoom-buttons {
  filter: none;
  gap: .5em;
  margin: .6em;
}
#zoom-buttons .svg-button {
  border-radius: var(--ot-btn-r);
  box-shadow: inset 0 0 0 2px var(--ot-edge), 0 3px 0 var(--ot-edge), var(--ot-gloss);
}

/* ==========================================================================
   侧边菜单：一张告示牌纸，顶上一条草地像素带
   ========================================================================== */
#app .side-menu {
  filter: none;
  background-color: var(--ot-paper);
  background-image:
    linear-gradient(90deg, var(--ot-paper-line) 0, var(--ot-paper-line) 1px, transparent 1px),
    linear-gradient(var(--ot-paper-line) 0, var(--ot-paper-line) 1px, transparent 1px);
  background-size: 28px 28px;
  box-shadow: inset -2px 0 0 var(--ot-edge), 8px 0 32px -10px rgba(0, 0, 0, .45);
  color: var(--ot-ink);
}
#app .side-menu::before {
  content: "";
  display: block;
  height: 14px;
  background: repeating-linear-gradient(90deg, #86d562 0, #86d562 14px, #6cc349 14px, #6cc349 28px);
  box-shadow: inset 0 -3px 0 rgba(42, 100, 28, .55);
}
#app .side-menu > .menu-button { top: 14px; border-radius: 0; box-shadow: none; }
#app .side-menu > .title {
  font-weight: 700;
  border-bottom: 2px solid var(--ot-edge);
  background: transparent;
}
#app .side-menu > .content { height: calc(100% - 4em - 16px); }
@media (max-width: 575.98px) {
  #app .side-menu > .content { height: calc(100% - 3em - 16px); }
}
#app .side-menu > .content hr { border-bottom: 2px solid var(--ot-edge); opacity: .6; }
#app .side-menu .simple-button { border-radius: 10px; margin: 2px 0; }
#app .side-menu .simple-button.active {
  background: var(--ot-tag-bg);
  box-shadow: inset 0 -2px 0 rgba(108, 195, 73, .4);
  color: var(--ot-tag-ink);
  font-weight: 700;
}
#app .side-menu input[type="text"],
#app .side-menu .text-input input {
  border: 2px solid var(--ot-edge);
  border-radius: var(--ot-btn-r);
  background: var(--ot-field);
  color: var(--ot-ink);
}

/* 统一账号：主菜单最上面的账号行（bluemap.js 放进去） */
#app .side-menu .ot-account {
  display: flex;
  align-items: center;
  gap: .6em;
  margin: .2em 0 .6em;
  padding: .45em .5em .55em .6em;
  border: 2px solid var(--ot-edge);
  border-radius: var(--ot-btn-r);
  background: var(--theme-bg-hover);
  line-height: 1.3;
}
#app .side-menu .ot-account-avatar {
  flex: none;
  width: 2em;
  height: 2em;
  box-sizing: border-box;
  border: 2px solid var(--ot-edge);
  border-radius: 8px;
  background: #fffdf8;
  image-rendering: pixelated;
}
#app .side-menu .ot-account-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#app .side-menu .ot-account-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#app .side-menu .ot-account-sub { font-size: .72em; font-weight: 600; color: var(--ot-ink-mute); }
#app .side-menu .ot-account-btn {
  flex: none;
  height: 2em;
  padding: 0 .8em;
  border-radius: 10px;
  border: 2px solid var(--ot-edge);
  background: linear-gradient(180deg, var(--ot-btn-top), var(--ot-btn-bottom));
  box-shadow: 0 3px 0 var(--ot-edge), var(--ot-gloss);
  color: var(--ot-ink);
  font: 700 .8em var(--ot-font);
  cursor: pointer;
}
#app .side-menu .ot-account-btn.is-primary,
#app .side-menu .ot-account-btn:hover {
  border-color: var(--ot-green-edge);
  background: linear-gradient(180deg, var(--ot-green-top), var(--ot-green-bottom));
  box-shadow: 0 3px 0 var(--ot-green-edge), inset 0 2px 0 rgba(255, 255, 255, .28);
  color: #fff;
}
#app .side-menu .ot-account-btn:active { transform: translateY(2px); }

/* ==========================================================================
   地图上的玩家、标记
   ========================================================================== */
#map-container .bm-marker-player { filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .45)); }
#map-container .bm-marker-player img {
  border-radius: 6px;
  box-shadow: 0 0 0 2px #fffdf8, 0 0 0 4px #201e1c;
}
#map-container .bm-marker-player .bm-player-name {
  top: -.7em;
  padding: .15em .6em;
  border-radius: 999px;
  border: 2px solid var(--ot-edge);
  background: var(--ot-paper);
  color: var(--ot-ink);
  font-family: var(--ot-font);
  font-weight: 700;
  white-space: nowrap;
}
#map-container .bm-marker-html .bm-marker-poi-label,
#map-container .bm-marker-labelpopup,
#map-container .bm-marker-popup {
  border: 2px solid var(--ot-edge);
  border-radius: var(--ot-btn-r);
  background-color: var(--ot-paper);
  color: var(--ot-ink);
  font-family: var(--ot-font);
  filter: drop-shadow(0 3px 0 var(--ot-edge)) drop-shadow(0 8px 12px rgba(0, 0, 0, .3));
}
#map-container .bm-marker-html .bm-marker-poi-label:after,
#map-container .bm-marker-labelpopup:after,
#map-container .bm-marker-popup:after { border-top-color: var(--ot-paper); }

/* ==========================================================================
   手机：Safari 状态栏、底部工具栏取页面最底层的颜色，和顶部控制条（纸面色）对齐
   ========================================================================== */
@media (max-width: 575.98px) {
  html { background-color: var(--ot-paper) !important; }
  #app .control-bar {
    height: calc(2em + 2px);
    box-shadow: inset 0 -2px 0 var(--ot-edge), 0 3px 0 var(--ot-edge);
  }
  #app .control-bar > :not(.space) { box-shadow: none; }
  #app .control-bar > :not(.space)::after { display: none; }
  #zoom-buttons { margin-bottom: calc(.6em + env(safe-area-inset-bottom, 0px)); }
}
