:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #ffffff;
  --ink: #151922;
  --muted: #8e9399;
  --line: #e1e4e8;
  --surface-muted: #f5f6f7;
  --accent: #005ac1;
  --accent-strong: #003a75;
  --word: #2b579a;
  --ppt: #b7472a;
  --excel: #217346;
  --warn: #9a3412;
  --shadow: 0 8px 24px rgba(31, 41, 55, 0.1);
}

@font-face {
  font-family: "OfficeOne Noto Sans KR";
  src: url("./fonts/noto/NotoSansKR-VF.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "OfficeOne Noto Serif KR";
  src: url("./fonts/serif/NotoSerifKR-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "OfficeOne Noto Sans JP";
  src: url("./fonts/noto/NotoSansJP-VF.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "OfficeOne Noto Sans SC";
  src: url("./fonts/noto/NotoSansSC-VF.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "OfficeOne Noto Sans Thai";
  src: url("./fonts/noto/NotoSansThai-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "OfficeOne Noto Sans Thai";
  src: url("./fonts/noto/NotoSansThai-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "OfficeOne Noto Sans Thai";
  src: url("./fonts/noto/NotoSansThai-Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "OfficeOne Noto Naskh Arabic";
  src: url("./fonts/noto/NotoNaskhArabic-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "OfficeOne Noto Naskh Arabic";
  src: url("./fonts/noto/NotoNaskhArabic-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "OfficeOne Noto Naskh Arabic";
  src: url("./fonts/noto/NotoNaskhArabic-Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "OfficeOne Noto Sans KR", "OfficeOne Noto Sans JP", "OfficeOne Noto Sans SC", "OfficeOne Noto Sans Thai", "OfficeOne Noto Naskh Arabic", sans-serif;
}

body {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

body.homeMode {
  grid-template-rows: 1fr;
  background: #000000;
}

body.embeddedMode,
body.embeddedMode.homeMode {
  grid-template-rows: auto 1fr;
  padding: 0;
  background: #e8eaed;
}

body.homeMode .toolbar,
body.homeMode .searchBar,
body.homeMode .sheetTabs {
  display: none;
}

body.embeddedMode .toolbar,
body.embeddedMode .searchBar,
body.embeddedMode .homeScreen {
  display: none;
}

body.presentationMode,
body.presentationMode.homeMode,
body.presentationMode.embeddedMode {
  grid-template-rows: 1fr;
  padding: 0;
  background: #000000;
}

body.presentationMode .toolbar,
body.presentationMode .searchBar,
body.presentationMode .sheetTabs {
  display: none;
}

body.presentationMode .stage {
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 0;
  background: #000000;
  touch-action: none;
}

body.presentationMode .canvasHost {
  margin: auto;
  box-shadow: none;
}

body.presentationMode .canvasHost.presentationTransition {
  opacity: 0;
  transform: translate(
    var(--presentation-enter-x, 24px),
    var(--presentation-enter-y, 0px)
  );
  transition: none;
}

body.presentationMode .canvasHost.presentationTransition.presentationTransitionActive {
  opacity: 1;
  transform: translateX(0);
  transition:
    opacity 180ms ease-out,
    transform 180ms ease-out;
}

.toolbar,
.searchBar {
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.searchBar {
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.titleBlock {
  min-width: 0;
  flex: 1;
}

.fileName {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 700;
}

.fileMeta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.toolbarActions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.button,
.iconButton {
  border: 1px solid var(--line);
  background: #f8fafc;
  color: var(--ink);
  height: 36px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
}

.button {
  padding: 0 12px;
}

.iconButton {
  width: 36px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.button:active,
.iconButton:active {
  background: #e9eef5;
}

.button:disabled,
.iconButton:disabled {
  color: #94a3b8;
  cursor: default;
  opacity: 0.58;
}

.fileInput {
  display: none;
}

.positionLabel {
  min-width: 70px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.iconButton.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.sheetTabs {
  display: none;
  gap: 6px;
  padding: 8px 12px;
  background: #f7f9fc;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.sheetTabs.visible {
  display: flex;
}

.sheetTab {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  border-radius: 6px;
  min-height: 32px;
  padding: 0 10px;
  font-weight: 650;
}

.sheetTab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.stage {
  position: relative;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 24px;
  touch-action: pan-x pan-y;
  overscroll-behavior: none;
  overscroll-behavior-x: none;
  overscroll-behavior-y: none;
  -webkit-overflow-scrolling: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.stage.horizontalScrollEnabled {
  overflow-x: auto;
}

.stage::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.scrollHandle {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  border-radius: 999px;
  background: rgba(21, 25, 34, 0.42);
  opacity: 0;
  transition:
    opacity 120ms ease,
    width 160ms ease,
    height 160ms ease,
    left 80ms linear,
    top 80ms linear,
    background 160ms ease;
}

.scrollHandle.hidden {
  display: none;
}

.scrollHandleVertical {
  width: 18px;
  min-height: 68px;
}

.scrollHandleHorizontal {
  height: 18px;
  min-width: 68px;
}

.scrollHandle.active {
  pointer-events: auto;
  opacity: 0.92;
  background: rgba(21, 25, 34, 0.74);
}

.pageScrollIndicator {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  right: calc(env(safe-area-inset-right) + 12px);
  z-index: 1100;
  min-width: 58px;
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.82);
  color: #ffffff;
  font-size: 13px;
  font-weight: 750;
  line-height: 1;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 140ms ease, transform 140ms ease;
}

.pageScrollIndicator.visible {
  opacity: 1;
  transform: translateY(0);
}

.scriptPanel {
  display: none;
}

.pageScript {
  display: none;
  width: 100%;
  min-height: 72px;
  margin-top: 10px;
  padding: 14px 16px;
  border: 1px solid #e3c84f;
  border-radius: 3px;
  background: #fff2a8;
  box-shadow: 0 2px 4px rgba(98, 78, 0, 0.16);
  color: #1f2933;
  font-size: 14px;
  line-height: 1.48;
  white-space: pre-wrap;
  box-sizing: border-box;
}

.pageScript.empty {
  display: none !important;
}

body.scriptMode:not(.presentationMode) .pageSurface {
  height: auto !important;
}

body.scriptMode:not(.presentationMode) .pageScript:not(.empty) {
  display: block;
}

.scriptText {
  overflow: auto;
  max-height: calc(min(32vh, 220px) - 24px);
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.42;
}

.scrollHandleVertical.active {
  width: 22px;
}

.scrollHandleHorizontal.active {
  height: 22px;
}

.homeMode .stage {
  padding: 0;
  background: #000000;
}

.embeddedMode .stage,
.embeddedMode.homeMode .stage {
  padding: 16px;
  background: #e8eaed;
}

.homeScreen {
  width: 100%;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  background: #000000;
  color: #f4eff8;
}

.homeTopbar {
  width: min(100%, 960px);
  min-height: 112px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 auto;
  padding: 32px 24px 16px;
  background: transparent;
}

.homeIconButton {
  flex: 0 0 auto;
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: #1d1d1d;
  cursor: pointer;
}

.homeIconButton:active,
.homeFileCard:active,
.homeTab:active {
  background: #262626;
}

.menuIcon {
  width: 24px;
  display: grid;
  gap: 5px;
}

.menuIcon span {
  display: block;
  height: 3px;
  border-radius: 2px;
  background: #f4eff8;
}

.sortIcon {
  width: 24px;
  height: 24px;
  position: relative;
  display: block;
}

.sortIcon span:nth-child(1),
.sortIcon span:nth-child(2) {
  position: absolute;
  left: 2px;
  width: 8px;
  height: 8px;
  border: 3px solid #f4eff8;
  border-radius: 3px;
}

.sortIcon span:nth-child(1) {
  top: 2px;
}

.sortIcon span:nth-child(2) {
  bottom: 2px;
}

.sortIcon span:nth-child(3) {
  position: absolute;
  right: 2px;
  top: 3px;
  width: 10px;
  height: 18px;
  border-right: 3px solid #f4eff8;
  border-bottom: 3px solid #f4eff8;
  transform: rotate(45deg);
  transform-origin: center;
}

.homeIconButton.descending .sortIcon {
  transform: scaleY(-1);
}

.homeSearch {
  flex: 1;
  min-width: 0;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  border: 2px solid #333333;
  border-radius: 29px;
  background: #1d1d1d;
}

.searchIcon {
  width: 22px;
  height: 22px;
  position: relative;
  flex: 0 0 auto;
  border: 4px solid #f4eff8;
  border-radius: 50%;
}

.searchIcon::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 4px;
  right: -10px;
  bottom: -5px;
  transform: rotate(45deg);
  transform-origin: left center;
  border-radius: 2px;
  background: #f4eff8;
}

.homeSearch input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: #f4eff8;
  font: inherit;
  font-size: 22px;
  font-weight: 600;
}

.homeSearch input::placeholder {
  color: #f4eff8;
  opacity: 1;
}

.homeTabs {
  width: min(100%, 960px);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  margin: 0 auto;
  padding: 10px 24px 0;
  background: transparent;
  border-bottom: 0;
}

.homeTab {
  min-width: 0;
  min-height: 92px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-bottom: 6px solid transparent;
  border-radius: 0;
  background: transparent;
  color: #a2a6ad;
  font-size: 20px;
  font-weight: 750;
  cursor: pointer;
}

.homeTab img {
  width: 34px;
  height: 34px;
  object-fit: contain;
  filter: grayscale(1) opacity(0.65);
}

.homeTab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.homeTab[data-home-format="word"].active {
  color: var(--word);
  border-bottom-color: var(--word);
}

.homeTab[data-home-format="ppt"].active {
  color: var(--ppt);
  border-bottom-color: var(--ppt);
}

.homeTab[data-home-format="excel"].active {
  color: var(--excel);
  border-bottom-color: var(--excel);
}

.homeTab.active img {
  filter: none;
}

.homeTab.hidden {
  display: none;
}

.homeError {
  margin: 18px auto 0;
  width: min(912px, calc(100% - 48px));
  padding: 10px 12px;
  border: 1px solid rgba(154, 52, 18, 0.24);
  border-radius: 8px;
  background: #fff7ed;
  color: var(--warn);
  font-size: 13px;
}

.homePanel {
  display: none;
  width: min(100%, 960px);
  flex: 1 0 auto;
  min-height: 0;
  align-items: flex-start;
  justify-content: stretch;
  margin: 0 auto;
  padding: 24px 24px 40px;
}

.homePanel.active {
  display: flex;
}

.homeFileCard {
  width: 100%;
  min-height: 138px;
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 22px;
  border: 0;
  border-radius: 28px;
  padding: 22px 26px;
  background: #1d1d1d;
  color: #f4eff8;
  text-align: left;
  cursor: pointer;
}

.homeFileIcon {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.homeFileIcon img {
  width: 56px;
  height: 56px;
  object-fit: contain;
}

.homeFileText {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.homeFileTitle {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 28px;
  font-weight: 800;
}

.homeFileMeta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #cbc6d0;
  font-size: 20px;
  font-weight: 500;
}

.homeFileMenu {
  width: 8px;
  display: grid;
  gap: 6px;
  justify-self: center;
}

.homeFileMenu span {
  width: 6px;
  height: 6px;
  display: block;
  border-radius: 50%;
  background: #cbc6d0;
}

.canvasHost {
  position: relative;
  margin: 0 auto;
  width: max-content;
  min-width: 320px;
  background: white;
  box-shadow: var(--shadow);
}

.canvasHost.continuousHost {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: transparent;
  box-shadow: none;
}

.canvasHost.sheetHost {
  min-width: 320px;
  margin: 0;
  overflow: visible;
  background: transparent;
  box-shadow: none;
}

.pageSurface {
  position: relative;
  flex: 0 0 auto;
  background: white;
  box-shadow: var(--shadow);
}

.zoomPreviewing .pageSurface,
.zoomPreviewing canvas,
.zoomPreviewing .textLayer {
  will-change: width, height, transform;
}

.canvasHost.errorHost {
  display: grid;
  place-items: center;
  min-width: min(360px, 100%);
  width: min(720px, 100%);
  min-height: 240px;
  background: transparent;
  box-shadow: none;
}

.pageErrorSurface {
  display: grid;
  place-items: center;
  padding: 24px;
  border: 1px solid #f0c7b5;
  background: #fff7ed;
}

.surfaceErrorPanel {
  max-width: min(520px, 100%);
  display: grid;
  gap: 8px;
  color: #7c2d12;
  text-align: center;
}

.surfaceErrorTitle {
  font-size: 16px;
  font-weight: 750;
}

.surfaceErrorMessage {
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.45;
}

.embeddedMode .canvasHost {
  max-width: none;
}

.embeddedMode .errorHost {
  min-width: min(320px, 100%);
  width: auto;
  min-height: 160px;
  display: grid;
  place-items: center;
  padding: 24px;
}

.embeddedError {
  position: static;
  color: #9a3412;
  font-size: 14px;
  font-weight: 650;
}

.passwordPromptOverlay {
  position: fixed;
  inset: 0;
  z-index: 1400;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(10, 13, 20, 0.38);
  backdrop-filter: blur(8px);
}

.passwordPrompt {
  width: min(360px, 100%);
  display: grid;
  gap: 12px;
  padding: 22px;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 18px 60px rgba(10, 13, 20, 0.28);
}

.passwordPromptIcon {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #ffffff;
  background: linear-gradient(135deg, #b7472a, #f97316);
  font-weight: 850;
  letter-spacing: 0;
}

.passwordPromptTitle {
  color: #151922;
  font-size: 19px;
  font-weight: 800;
}

.passwordPromptMessage {
  color: #5f6673;
  font-size: 13px;
  line-height: 1.45;
}

.passwordPromptInput {
  height: 48px;
  border: 1px solid #d7dce5;
  border-radius: 8px;
  padding: 0 12px;
  color: #151922;
  font-size: 16px;
}

.passwordPromptInput:focus {
  outline: 2px solid rgba(183, 71, 42, 0.22);
  border-color: #b7472a;
}

.passwordPromptActions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.passwordOpenButton {
  border-color: #b7472a;
  background: #b7472a;
  color: #ffffff;
}

.hidden {
  display: none;
}

canvas {
  display: block;
  background: white;
}

.textLayer {
  position: absolute;
  inset: 0;
  pointer-events: auto;
}

.textSpan {
  position: absolute;
  color: transparent;
  user-select: text;
  white-space: pre;
  unicode-bidi: plaintext;
}

.textSpan.searchMatch {
  background: rgba(255, 213, 79, 0.62);
  border-radius: 2px;
  outline: 1px solid rgba(245, 158, 11, 0.48);
}

.searchInput {
  flex: 1;
  min-width: 120px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  font-size: 14px;
}

.searchStatus {
  min-width: 100px;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.error {
  color: var(--warn);
}

@media (max-width: 720px) {
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbarActions {
    width: 100%;
    overflow-x: auto;
  }

  .stage {
    padding: 12px;
  }

  .homeMode .stage {
    padding: 0;
  }

  .homeTopbar {
    min-height: 92px;
    gap: 10px;
    padding: 24px 16px 12px;
  }

  .homeIconButton {
    width: 48px;
    height: 48px;
  }

  .homeSearch {
    height: 48px;
    gap: 10px;
    padding: 0 16px;
  }

  .homeSearch input {
    font-size: 18px;
  }

  .searchIcon {
    width: 18px;
    height: 18px;
    border-width: 3px;
  }

  .searchIcon::after {
    width: 10px;
    height: 3px;
    right: -8px;
    bottom: -4px;
  }

  .homeTabs {
    padding: 8px 16px 0;
  }

  .homeTab {
    min-height: 76px;
    border-bottom-width: 5px;
    font-size: 16px;
  }

  .homeTab img {
    width: 28px;
    height: 28px;
  }

  .homePanel {
    padding: 18px 16px 32px;
  }

  .homeFileCard {
    min-height: 112px;
    grid-template-columns: 68px minmax(0, 1fr) 24px;
    gap: 14px;
    border-radius: 20px;
    padding: 18px;
  }

  .homeFileIcon {
    width: 58px;
    height: 58px;
  }

  .homeFileIcon img {
    width: 46px;
    height: 46px;
  }

  .homeFileTitle {
    font-size: 23px;
  }

  .homeFileMeta {
    font-size: 17px;
  }

  .searchStatus {
    min-width: 64px;
  }
}
