:root {
  --xl-green: #107c41;
  --xl-green-dark: #0e6b38;
  --grid: #d4d4d4;
  --head-bg: #f5f5f5;
  --head-bd: #c6c6c6;
  --sel: #217346;
  --text: #212121;
  --cell-w: 76px;
  --cell-h: 22px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #fff;
  color: var(--text);
  font-family: "Malgun Gothic", "맑은 고딕", -apple-system, "Apple SD Gothic Neo",
    "Segoe UI", Roboto, sans-serif;
  font-size: 12px;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ── 타이틀바 / 리본 ─────────────────────────────── */
.ribbon { flex: none; user-select: none; }

.titlebar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 30px;
  padding: 0 8px;
  background: var(--xl-green);
  color: #fff;
}
.qat { display: flex; align-items: center; gap: 10px; }
.xl-badge {
  display: grid;
  place-items: center;
  width: 18px; height: 18px;
  border-radius: 3px;
  background: #fff;
  color: var(--xl-green);
  font-weight: 700;
  font-size: 12px;
}
.qat-btn { opacity: .8; font-size: 13px; }
.doc-title {
  flex: 1;
  text-align: center;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.saved { opacity: .75; }
.win-ctl { display: flex; gap: 14px; font-size: 11px; opacity: .9; }

.tabs {
  display: flex;
  gap: 2px;
  padding: 0 6px;
  background: var(--xl-green);
  color: #fff;
  font-size: 12px;
}
.tabs span {
  padding: 5px 11px 7px;
  border-radius: 4px 4px 0 0;
  white-space: nowrap;
}
.tabs .active { background: #fff; color: var(--text); font-weight: 600; }

.ribbon-body {
  display: flex;
  align-items: stretch;
  gap: 0;
  height: 76px;
  padding: 4px 6px 0;
  background: #fff;
  border-bottom: 1px solid var(--head-bd);
  overflow: hidden;
}
.rgroup {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 4px 10px 2px;
  border-right: 1px solid #e6e6e6;
}
.rg-items { display: flex; align-items: center; gap: 4px; flex: 1; }
.rg-items.font-row { gap: 3px; }
.rg-label { text-align: center; color: #757575; font-size: 10px; padding-top: 2px; }
.ri {
  display: inline-grid;
  place-items: center;
  height: 24px;
  padding: 0 7px;
  border-radius: 3px;
  color: #333;
  white-space: nowrap;
}
.ri.sq { width: 26px; padding: 0; }
.ri.wide { height: 44px; flex-direction: column; font-size: 11px; }
.ri:hover { background: #f0f0f0; }
.fake-select {
  height: 22px;
  border: 1px solid #d0d0d0;
  border-radius: 2px;
  background: #fff;
  font: inherit;
  font-size: 11px;
  padding: 0 2px;
  width: 92px;
  pointer-events: none;
}
.fake-select.narrow { width: 44px; }

/* ── 보호된 보기 줄 ───────────────────────────────── */
.protected-bar {
  flex: none;
  display: none;
  align-items: center;
  gap: 8px;
  height: 26px;
  padding: 0 10px;
  background: #fff4ce;
  border-bottom: 1px solid #e6d08a;
  color: #4a3c0a;
  font-size: 11px;
  user-select: none;
}
body.boss .protected-bar { display: flex; }
body.rec .protected-bar { display: none !important; }   /* 촬영 모드: 반전 스포 방지 */
.pb-icon { color: #b58b00; font-size: 12px; }
.pb-text { flex: none; }
.pb-keys { margin-left: auto; color: #6b5a1a; }
.pb-keys kbd {
  display: inline-block;
  padding: 1px 5px;
  margin: 0 1px;
  border: 1px solid #c9b169;
  border-bottom-width: 2px;
  border-radius: 3px;
  background: #fffdf4;
  font-family: inherit;
  font-size: 10px;
  font-weight: 600;
}

/* ── 수식 입력줄 ──────────────────────────────────── */
.formula-bar {
  flex: none;
  display: flex;
  align-items: center;
  height: 24px;
  border-bottom: 1px solid var(--head-bd);
  background: #fff;
  user-select: none;
}
.namebox {
  width: 118px;
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 8px;
  border-right: 1px solid var(--head-bd);
  font-size: 11px;
}
.fx {
  width: 34px;
  display: grid;
  place-items: center;
  border-right: 1px solid var(--head-bd);
  height: 100%;
  font-style: italic;
  color: #666;
  font-size: 11px;
}
.formula {
  flex: 1;
  padding: 0 8px;
  font-size: 11px;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
}

/* ── 시트 ─────────────────────────────────────────── */
.sheet-wrap {
  flex: 1;
  overflow: auto;
  background: #fff;
}
.sheet {
  border-collapse: collapse;
  table-layout: fixed;
  user-select: none;
}
.sheet th, .sheet td {
  border-right: 1px solid var(--grid);
  border-bottom: 1px solid var(--grid);
  height: var(--cell-h);
  padding: 0;
  font-weight: 400;
  font-size: 11px;
}

/* 열/행 머리글 */
.sheet thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--head-bg);
  border-bottom: 1px solid var(--head-bd);
  color: #444;
  text-align: center;
  width: var(--cell-w);
  font-size: 11px;
}
.sheet thead th.corner {
  left: 0;
  z-index: 3;
  width: 34px;
  min-width: 34px;
}
.sheet tbody th.rowhead {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--head-bg);
  border-right: 1px solid var(--head-bd);
  color: #444;
  text-align: center;
  width: 34px;
  min-width: 34px;
}
.sheet thead th.hl, .sheet tbody th.rowhead.hl {
  background: #d3e3d9;
  color: var(--xl-green-dark);
  font-weight: 600;
}

/* 셀 */
.cell {
  width: var(--cell-w);
  text-align: right;
  padding: 0 6px;
  background: #fff;
  cursor: cell;
  position: relative;
  overflow: hidden;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.cell.selected {
  outline: 2px solid var(--sel);
  outline-offset: -2px;
  z-index: 1;
}

/* 데이터 영역 밖 빈 셀 */
.cell.pad { cursor: cell; background: #fff; }

/* 표 머리행 / 머리열 */
.cell.thead-cell {
  background: #e8eef1;
  font-weight: 600;
  color: #1f3a4d;
}
.cell.center { text-align: center; }
.cell.left { text-align: left; }

/* ── 게임 모드: 전통 지뢰찾기 룩 ──────────────────────
   안 눌린 셀 = 회색 돌출 버튼, 열린 셀 = 눌린 평면 + 굵은 색 숫자.
   Esc(위장 모드)를 누르면 아래 body.boss 규칙이 전부 평평한 엑셀로 되돌린다. */
.cell.tile {
  background: #c4c4c4;
  box-shadow: inset 2px 2px 0 #efefef, inset -2px -2px 0 #8a8a8a;
}

/* 열린 셀 = 눌린 평면 */
.cell.open {
  background: #e9e9e9;
  text-align: center;
  font-weight: 700;
}
.cell.open.zero { color: transparent; }      /* 빈 칸 */
.cell.n1 { color: #1a56c4; }
.cell.n2 { color: #1a7a2e; }
.cell.n3 { color: #d0201a; }
.cell.n4 { color: #12237a; }
.cell.n5 { color: #7a1a12; }
.cell.n6 { color: #0f8a86; }
.cell.n7 { color: #111; }
.cell.n8 { color: #7a7a7a; }

/* 깃발 = 빨간 삼각기 */
.cell.flag {
  text-align: center;
}
.cell.flag::after {
  content: "🚩";
  font-size: 12px;
  line-height: 1;
}

/* 지뢰 = 폭발한 오류 셀 */
.cell.ref {
  color: #fff;
  background: #d0201a;
  font-weight: 700;
  text-align: center;
  padding: 0 2px;
  font-size: 10px;
}
.cell.ref.boom { background: #000; }
.cell.ref::before { content: "💥 "; }

/* ── 위장 모드(Esc): 전부 평평한 엑셀로 되돌린다 ─────── */
body.boss .cell.tile { background: #fff; box-shadow: none; }
body.boss .cell.open { background: #fbfbfb; text-align: right; font-weight: 400; }
body.boss .cell.open.zero { color: #a8a8a8; }
body.boss .cell.flag { text-align: right; }
body.boss .cell.flag::after { display: none; }
body.boss .cell.ref { color: var(--text); background: #fbfbfb; font-weight: 400; text-align: right; padding: 0 6px; font-size: 11px; }
body.boss .cell.ref::before { content: ""; }
body.boss .cell.n1, body.boss .cell.n2, body.boss .cell.n3, body.boss .cell.n4,
body.boss .cell.n5, body.boss .cell.n6, body.boss .cell.n7, body.boss .cell.n8 { color: var(--text); }
body.boss .cell { cursor: default; }
body.boss #dialog-backdrop { display: none !important; }

/* ── 시트 탭 / 상태바 ─────────────────────────────── */
.sheet-tabs {
  flex: none;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 26px;
  padding: 0 8px;
  border-top: 1px solid var(--head-bd);
  background: #f0f0f0;
  user-select: none;
}
.sheet-tabs .nav { color: #888; margin-right: 8px; letter-spacing: 2px; font-size: 10px; }
.stab {
  padding: 4px 12px;
  font-size: 11px;
  color: #555;
  border-radius: 3px 3px 0 0;
}
.stab.active { background: #fff; color: var(--xl-green-dark); font-weight: 600; }
.stab.plus { color: #888; }

.statusbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 24px;
  padding: 0 12px;
  border-top: 1px solid var(--head-bd);
  background: #f0f0f0;
  color: #444;
  font-size: 11px;
  user-select: none;
}
.statusbar .spacer { flex: 1; }
.statusbar .zoom { color: #666; }

/* ── 대화상자 ─────────────────────────────────────── */
#dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .08);
  display: grid;
  place-items: center;
  z-index: 50;
}
#dialog-backdrop[hidden] { display: none; }
#dialog {
  width: 340px;
  background: #f0f0f0;
  border: 1px solid #999;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .28);
  font-size: 12px;
}
.dlg-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 26px;
  padding: 0 8px;
  background: #fff;
  border-bottom: 1px solid #ddd;
  font-weight: 600;
}
.dlg-x { color: #666; cursor: default; }
.dlg-body {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 18px 16px;
  background: #fff;
}
.dlg-icon {
  flex: none;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: #d13438;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 17px;
  font-weight: 700;
}
.dlg-icon.ok { background: var(--xl-green); }
.dlg-msg { line-height: 1.55; padding-top: 3px; }
.dlg-foot {
  display: flex;
  justify-content: flex-end;
  padding: 10px 16px;
  border-top: 1px solid #e0e0e0;
}
.dlg-foot button {
  min-width: 84px;
  height: 26px;
  border: 1px solid #adadad;
  border-radius: 2px;
  background: #e1e1e1;
  font: inherit;
  cursor: pointer;
}
.dlg-foot button:hover { background: #d5d5d5; }

/* ── 모바일 안내 ──────────────────────────────────── */
#mobile-note {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: #1f1f1f;
  color: #fff;
  font-size: 12px;
  line-height: 1.5;
  box-shadow: 0 -6px 20px rgba(0, 0, 0, .25);
}
#mobile-note[hidden] { display: none; }
#mobile-note strong { flex: none; }
#mobile-note span { flex: 1; opacity: .9; }
#mobile-note b { color: #7ee2a8; }
#mobile-note button {
  flex: none;
  height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 4px;
  background: var(--xl-green);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
#mobile-note #dismiss-note {
  width: 30px;
  padding: 0;
  background: transparent;
  color: #999;
  font-size: 14px;
}

@media (max-width: 760px) {
  :root { --cell-w: 44px; --cell-h: 30px; }
  .ribbon-body, .tabs { display: none; }
  .namebox { width: 74px; }
  .sheet-wrap { padding-bottom: 64px; }
}
