:root {
  --wall: #ECEDEE;
  --side: #E6E7E8;
  --ink: #1B1B1B;
  --gray: #55595E;
  --red: #C8102E;
  --bar: 64px;
  --panel: clamp(236px, 22vw, 340px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--wall);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

canvas {
  position: fixed;
  left: 0;
  top: 0;
  touch-action: none;
}

button { font: inherit; color: inherit; cursor: pointer; }

button.t {
  height: 44px;
  padding: 0 14px;
  background: none;
  border: 0;
  font-size: 15px;
  white-space: nowrap;
}
button.t.u { text-decoration: underline; text-underline-offset: 6px; }
button.t:hover { color: #000; text-decoration: underline; text-underline-offset: 6px; }
button.t.s { padding: 0 8px; font-size: 13px; color: var(--gray); }

button.o {
  height: 44px;
  padding: 0 18px;
  background: var(--wall);
  border: 1px solid var(--ink);
  font-size: 15px;
}
button.o:hover { background: var(--ink); color: var(--wall); }

.dot {
  display: inline-block;
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
}

.gray { color: var(--gray); }

/* 顶栏：字直接写在墙上，底下只有一段从墙色到透明的过渡，免得被拖过来的拼图块盖住看不清 */
.bar {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 2;
  height: var(--bar);
  padding: 0 14px 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: linear-gradient(var(--wall) 62%, rgba(236, 237, 238, 0));
  pointer-events: none;
}
.bar > * { pointer-events: auto; }

.lead { display: flex; align-items: baseline; gap: 24px; min-width: 0; }
.brand { font-size: 20px; font-weight: 500; letter-spacing: 8px; white-space: nowrap; }
.info { display: flex; align-items: baseline; gap: 10px; font-size: 15px; font-weight: 500; white-space: nowrap; }
.info .gray { font-size: 13px; font-weight: 400; }

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.status .sep { color: var(--gray); margin-left: 10px; }

.actions { display: flex; gap: 2px; }

/* 定位置用的一层：左边（或上边）是墙面，右边（或下边）是搁板一栏 */
.stage {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--bar);
  bottom: 0;
  z-index: 1;
  display: flex;
  flex-direction: row;
  pointer-events: none;
}
#wall-area { position: relative; flex: 1; min-width: 0; min-height: 0; margin-bottom: 10px; }
#panel-area { flex: none; width: var(--panel); min-height: 0; display: flex; flex-direction: column; }
#tray-area { flex: 1; min-height: 0; }

.shelf-head { flex: none; padding: 4px 8px 2px 12px; }
.tabs { display: flex; flex-wrap: wrap; gap: 2px; }
.tabs button {
  pointer-events: auto;
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  min-width: 44px;
  height: 44px;
  padding: 0 8px;
  background: none;
  border: 0;
  border-bottom: 1px solid rgba(27, 27, 27, 0.15);
  font-size: 16px;
  font-weight: 300;
  line-height: 44px;
  color: var(--gray);
}
.tabs button small { font-size: 11px; font-weight: 400; font-variant-numeric: tabular-nums; }
.tabs button[aria-selected="true"] { border-bottom: 2px solid var(--ink); color: var(--ink); font-weight: 700; }
.tabs button.hot { background: rgba(200, 16, 46, 0.12); border-bottom: 2px solid var(--red); color: var(--ink); }
.tools { display: flex; gap: 0; margin-left: -8px; }
.tools button { pointer-events: auto; height: 40px; }

.hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 6px;
  text-align: center;
  font-size: 13px;
  color: var(--gray);
}

/* 拼完以后的说明牌：占搁板那一栏的位置，字直接写在墙上，不盖住画 */
.plaque {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 16px 44px 22px;
  pointer-events: auto;
}
.plaque h2 { margin: 0 0 4px; font-size: 19px; font-weight: 500; letter-spacing: 1px; }
.plaque .gray { font-size: 13px; }
.plaque .result { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 14px; font-variant-numeric: tabular-nums; }
.plaque .links { display: flex; gap: 2px; margin-left: -14px; }
.plaque #done-record { margin-top: 2px; }
.plaque .enter { display: flex; gap: 8px; margin-top: 14px; }
.plaque .enter input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 2px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--ink);
  border-radius: 0;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}
.plaque .enter input:focus { border-bottom-width: 2px; }
.plaque .enter input::placeholder { color: #8A8E93; }
.plaque .enter .hp { position: absolute; left: -9999px; width: 1px; height: 1px; flex: none; }
.plaque .enter button { flex: none; padding: 0 6px 0 10px; }
.plaque .enter button:disabled { color: #8A8E93; cursor: default; }
.plaque #board-msg { margin-top: 8px; min-height: 18px; }
.plaque #board-msg.err { color: var(--red); }
.plaque .links { flex-wrap: wrap; }
/* 说明牌一行行出现 */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
body.is-done .plaque .what > *, body.is-done .plaque .links { animation: rise 0.5s ease both; }
body.is-done .plaque .what > :nth-child(2) { animation-delay: 0.12s; }
body.is-done .plaque .what > :nth-child(3) { animation-delay: 0.24s; }
body.is-done .plaque .what > :nth-child(4) { animation-delay: 0.36s; }
body.is-done .plaque .links { animation-delay: 0.5s; }
@media (prefers-reduced-motion: reduce) {
  body.is-done .plaque .what > *, body.is-done .plaque .links { animation: none; }
}

.bar, .stage { transition: opacity 0.35s ease; }
body.finale .bar, body.finale .stage { opacity: 0; }

/* 拼完时的灯光：一块和画框一样大的透明区域，四周用很大的阴影压暗 */
#lights { position: fixed; inset: 0; z-index: 20; overflow: hidden; cursor: pointer; }
#lights i { position: absolute; display: block; border-radius: 3px; box-shadow: 0 0 90px 9999px rgba(12, 12, 14, 0.78); }

body.is-done .shelf-head,
body.is-done #tray-area { display: none; }
body.is-done #panel-area { justify-content: flex-end; }

/* 选画和看原图：整面墙换一幅内容 */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--wall);
  padding: 10px 28px 56px;
}
.sheet-head, .count-row, .note, .works { max-width: 1080px; margin-left: auto; margin-right: auto; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; height: 54px; }
.sheet-head h2 { margin: 0; font-size: 20px; font-weight: 500; letter-spacing: 6px; }
.sheet-head .tally { flex: 1; margin-left: 18px; font-size: 13px; }
.board-body { max-width: 560px; margin: 14px auto 0; }
.board-body .counts button { width: 72px; font-size: 16px; }
.counts button[aria-selected="true"] { border-bottom: 2px solid var(--ink); color: var(--ink); font-weight: 700; }
.rank { list-style: none; margin: 18px 0 0; padding: 0; }
.rank li {
  display: flex;
  align-items: baseline;
  gap: 14px;
  height: 46px;
  line-height: 46px;
  border-bottom: 1px solid rgba(27, 27, 27, 0.1);
  font-size: 16px;
}
.rank .rk { width: 28px; font-size: 13px; color: var(--gray); font-variant-numeric: tabular-nums; }
.rank li:nth-child(-n+3) .rk { color: var(--ink); font-weight: 700; }
.rank .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .tm { font-variant-numeric: tabular-nums; }
.rank li.me .nm { font-weight: 700; }
.rank li.me .nm::after { content: "（你）"; font-weight: 400; font-size: 13px; color: var(--gray); }
.work .marks { display: flex; align-items: baseline; gap: 9px; margin-top: 6px; font-size: 12px; color: #8A8E93; font-variant-numeric: tabular-nums; }
.work .marks b { font-weight: 700; color: var(--ink); }
.work .marks .best { margin-left: auto; color: var(--gray); }
.sheet-head button.t { margin-right: -14px; }

.count-row { display: flex; align-items: center; gap: 18px; margin-top: 10px; }
.count-row .label { font-size: 13px; color: var(--gray); letter-spacing: 2px; }
.counts { display: flex; gap: 6px; }
.counts button {
  width: 54px;
  height: 44px;
  padding: 0;
  background: none;
  border: 0;
  border-bottom: 1px solid rgba(27, 27, 27, 0.15);
  font-size: 18px;
  font-weight: 300;
  color: var(--gray);
}
.counts button[aria-pressed="true"] { border-bottom: 2px solid var(--ink); color: var(--ink); font-weight: 700; }

.note { margin-top: 14px; margin-bottom: 0; font-size: 13px; color: var(--gray); }

.works {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 40px 36px;
  margin-top: 30px;
}
.work { display: block; padding: 0; background: none; border: 0; text-align: left; }
.work .fr {
  display: block;
  padding: 9px;
  border: 5px solid var(--ink);
  background: #FAFAF8;
  box-shadow: 0 12px 18px rgba(0, 0, 0, 0.16);
  transition: transform 0.15s ease;
}
.work:hover .fr { transform: translateY(-3px); }
.work img { display: block; width: 100%; aspect-ratio: 3 / 2; object-fit: cover; }
.work .cap { display: flex; align-items: center; gap: 8px; margin-top: 14px; font-size: 14px; }
.work .cap.gray { font-size: 12px; }
.work .blank {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 3 / 2;
  background: #E1E2E0;
  font-size: 15px;
  letter-spacing: 2px;
}

.sheet.center { display: flex; align-items: center; justify-content: center; padding: 20px; cursor: pointer; }
.sheet.center figure { margin: 0; }
.sheet.center img {
  display: block;
  max-width: min(92vw, 1100px);
  max-height: calc(100vh - 120px);
  padding: 12px;
  border: 6px solid var(--ink);
  background: #FAFAF8;
  box-shadow: 0 18px 26px rgba(0, 0, 0, 0.18);
}
.sheet.center figcaption { display: flex; justify-content: space-between; gap: 16px; margin-top: 16px; font-size: 14px; }

@media (max-width: 1099px) {
  .info { display: none; }
}

/* 矮的横屏（手机横过来）：顶栏和搁板一栏都收窄 */
@media (max-height: 520px) and (min-aspect-ratio: 1/1) {
  :root { --bar: 48px; --panel: 212px; }
  .bar { padding: 0 8px 0 16px; }
  .brand { font-size: 17px; letter-spacing: 5px; }
  .status .sep { display: none; }
  button.t { padding: 0 9px; font-size: 14px; }
}

/* 竖屏：搁板在底部一条，按钮在最下面一排 */
@media (max-aspect-ratio: 1/1) {
  :root { --bar: 52px; }
  .bar { padding: 0 16px; }
  .brand { font-size: 17px; letter-spacing: 5px; }
  .status { font-size: 13px; }
  .actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(50px + env(safe-area-inset-bottom));
    padding: 0 4px env(safe-area-inset-bottom);
    align-items: center;
    justify-content: space-around;
    background: var(--side);
  }
  button.t { padding: 0 8px; }
  .stage { flex-direction: column; bottom: calc(50px + env(safe-area-inset-bottom)); }
  #wall-area { margin-bottom: 0; }
  #panel-area { width: auto; }
  #tray-area { flex: none; height: 112px; }
  .shelf-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 4px; padding: 0 4px 0 10px; }
  .tools { margin-left: 0; flex: none; }
  .tools button { height: 44px; }
  .hint { font-size: 12px; }
  .plaque { gap: 2px; padding: 10px 16px 2px 16px; }
  .plaque h2 { display: inline; margin-right: 10px; font-size: 17px; }
  .plaque #done-spec { display: inline; }
  .plaque .result { margin-top: 6px; }
  .plaque .enter { margin-top: 8px; }
  .plaque #board-msg { margin-top: 4px; min-height: 0; }
  .plaque .links { margin-left: -8px; }
  .work .marks { gap: 6px; flex-wrap: wrap; }
  .sheet { padding: 6px 16px 48px; }
  .works { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px 18px; margin-top: 24px; }
  .work .fr { padding: 6px; border-width: 4px; }
  .counts button { width: 48px; }
  .count-row { gap: 12px; }
}
