:root {
  --bg: #d9d9d9;
  --fg: #111;
  --card: #fff;
  --line: #111;
  --sel: rgba(0, 0, 0, .22);
  --ov: #e4e4e4;
  --ovfg: #111;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #2a2a2a;
    --fg: #eee;
    --card: #fff;
    --line: #eee;
    --sel: rgba(0, 0, 0, .28);
  }
}

:root[data-theme="dark"] {
  --bg: #2a2a2a;
  --fg: #eee;
  --card: #fff;
  --line: #eee;
  --sel: rgba(0, 0, 0, .28);
}

html {
  scroll-padding-top: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  display: flex;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
}

.wrap {
  width: 100%;
  margin: 0 auto;
  padding: 10px 12px 16px;
}

.wrap.wide {
  max-width: min(1000px, calc((100dvh - 100px) * 1.7));
}

.wrap.tall {
  max-width: min(460px, calc((100dvh - 100px) * .75));
}

.top {
  display: flex;
  justify-content: space-between;
  font-weight: 800;
  font-size: 18px;
  margin-bottom: 6px;
}

.bar {
  height: 8px;
  background: rgba(128, 128, 128, .35);
  border-radius: 5px;
  overflow: hidden;
  margin-bottom: 8px;
}

.bar i.bar-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--fg);
  transition: width 1s linear;
}

.board {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 1px;
  background: #8a8a8a;
  border-radius: 12px;
  padding: 4px;
  touch-action: none;
  border: 3px solid var(--line);
}

.board .c img {
  width: 100%;
  height: 100%;
  object-fit: contain; /* 이미지 비율을 깨뜨리지 않고 딱 맞춰서 채움 */
  display: block;
  pointer-events: none; /* 클릭 이벤트가 이미지에 간섭하지 않도록 방지 */
}

.c {
  aspect-ratio: 1;
  background: var(--card);
  border-radius: 4px;
  overflow: hidden;
  transition: transform .25s, opacity .25s;
}

.c img {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  filter: grayscale(0);
}

.c.sel {
  background: #9a9a9a;
}

.c.sel img {
  mix-blend-mode: multiply;
}

.c.pop {
  transform: scale(0);
  opacity: 0;
}

.c.empty {
  visibility: hidden;
}

.board.shake {
  animation: sh .25s;
}

@keyframes sh {
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.ov {
  position: fixed;
  inset: 0;
  background: var(--ov);
  color: var(--ovfg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
  z-index: 5;
  overflow: auto;
}

.ov.hide {
  display: none;
}

.ov h1 {
  margin: 0 0 8px;
  color: #111;
  font-size: 28px;
}

.ov p {
  margin: 4px 0;
  line-height: 1.5;
  max-width: 340px;
}

.sheet {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 14px 0;
  width: 100%;
  max-width: 330px;
}

.sheet img {
  width: 100%;
  border-radius: 10px;
  display: block;
  background: #fff;
}

.res {
  display: none;
  flex-direction: column;
  align-items: center;
}

.res .lb {
  font-size: 22px;
  letter-spacing: .3em;
  opacity: .8;
}

.res .big {
  font-size: clamp(96px, 32vw, 170px);
  font-weight: 900;
  line-height: 1;
  margin: 4px 0;
}

.res .best {
  font-size: 16px;
  opacity: .8;
  margin-bottom: 8px;
}

.msg {
  flex: 1;
  text-align: center;
  font-weight: 700;
  margin: 0;
  height: auto;
}

.foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  min-height: 38px;
}

.c.hint {
  z-index: 10 !important;
  outline: 3px solid #ffeb3b !important;
  background-color: rgba(255, 253, 235, 0.90) !important;
  box-shadow: 0 0 5px #ffeb3b !important; 
  transform: scale(1);
  transition: all 0.2s ease-in-out;
}

.hint-btn {
  font-size: 15px;
  padding: 8px 16px;
  margin: 0;
  background: var(--fg);
  color: var(--bg);
}

.hint-btn:disabled {
  opacity: .35;
}

.c.hint {
  background: #888;
  box-shadow: inset 0 0 0 3px var(--line);
  animation: bl .5s 3;
}

@keyframes bl {
  50% { background: #ddd; }
}

.dif {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.dif button {
  font-size: 16px;
  padding: 9px 18px;
  margin: 0;
  background: transparent;
  color: #111;
  border: 2px solid #111;
}

.dif button.on {
  background: #111;
  color: #e4e4e4;
}

.dd {
  font-size: 13px;
  opacity: .75;
  margin-top: 6px;
}

button {
  font: inherit;
  font-weight: 800;
  font-size: 20px;
  background: var(--ovfg);
  color: var(--ov);
  border: 0;
  border-radius: 28px;
  padding: 14px 44px;
  margin-top: 12px;
}

@media (max-width: 768px) {
.wrap {
  padding: 6px 4px 12px;
}
.wrap.tall,
.wrap.wide {
  max-width: 100% !important; 
}

.board {
  padding: 2px;
  gap: 1px; 
  border-width: 2px; 
}

.top {
  font-size: 16px;
  margin-bottom: 4px;
}

.res .big {
    font-size: clamp(60px, 25vw, 120px);
  }
}