:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --panel-2: #f0f3f2;
  --text: #1c2422;
  --muted: #65736f;
  --line: #d9dfdc;
  --accent: #1f8a6b;
  --accent-2: #d84e3f;
  --shadow: 0 16px 42px rgba(28, 36, 34, 0.12);
  --radius: 8px;
  --zoom: 1;
  --surface-width: 100%;
  --answer-height: 380px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", sans-serif;
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px 18px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  min-height: 100vh;
}

.brand {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.brand h1 {
  margin: 2px 0 0;
  font-size: 24px;
  line-height: 1.16;
  letter-spacing: 0;
}

.brand__overline {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.brand__count {
  min-width: 54px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
}

.modeTabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius);
  background: var(--panel-2);
}

.modeTabs__button {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.modeTabs__button.is-active {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(28, 36, 34, 0.12);
}

.jumpBox {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.jumpBox input {
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  outline: none;
}

.jumpBox input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 138, 107, 0.15);
}

.selector {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  align-content: start;
  overflow-y: auto;
  padding-right: 2px;
}

.selector[data-mode="page"] {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.selectButton {
  position: relative;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font-size: 15px;
  font-weight: 800;
}

.selectButton:hover {
  border-color: rgba(31, 138, 107, 0.45);
}

.selectButton.is-active {
  border-color: var(--accent);
  background: #e7f4ef;
  color: #0d5f49;
}

.selectButton.is-taught::after {
  content: "";
  position: absolute;
  right: 7px;
  top: 7px;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--accent-2);
}

.selectButton.is-annotated::before {
  content: "";
  position: absolute;
  left: 7px;
  bottom: 7px;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #2367d1;
}

.main {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
  min-height: 100vh;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 76px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 244, 0.92);
  backdrop-filter: blur(10px);
}

.toolbar__spacer {
  flex: 1;
}

.titleBlock {
  min-width: 0;
}

.titleBlock p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.titleBlock h2 {
  margin: 2px 0 0;
  overflow: hidden;
  font-size: 20px;
  line-height: 1.22;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.iconButton,
.toolButton,
.zoomReadout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
}

.iconButton svg,
.toolButton svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toolButton {
  gap: 7px;
  padding: 0 12px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.toolButton.is-active {
  border-color: var(--accent);
  background: #e7f4ef;
  color: #0d5f49;
}

.inkbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.inkbar .toolButton,
.inkbar__group,
.sizeControl {
  flex: 0 0 auto;
}

.inkbar .toolButton {
  white-space: nowrap;
}

.inkbar__group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  border-radius: 10px;
  background: var(--panel-2);
}

.colorSwatch {
  width: 34px;
  min-width: 34px;
  height: 34px;
  border: 2px solid transparent;
  border-radius: 999px;
  background: #1c2422;
}

.colorSwatch--red {
  background: #d84e3f;
}

.colorSwatch--blue {
  background: #2367d1;
}

.colorSwatch.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 138, 107, 0.16);
}

.sizeControl {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 148px;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
}

.sizeControl input {
  width: 84px;
  accent-color: var(--accent);
}

.saveStatus {
  min-width: 68px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.saveStatus.is-error {
  color: var(--accent-2);
}

.zoomGroup {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 10px;
  background: var(--panel-2);
}

.zoomGroup .iconButton,
.zoomReadout {
  border: 0;
  background: transparent;
}

.zoomReadout {
  min-width: 62px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.stage {
  overflow: auto;
  padding: 26px;
  min-width: 0;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

.stage__inner {
  min-height: calc(100vh - 190px);
  width: 100%;
  min-width: 0;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
}

.workSurface {
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
  gap: 16px;
  min-width: 0;
  width: var(--surface-width);
  flex: 0 0 var(--surface-width);
  max-width: none;
  margin-inline: auto;
}

.imageFrame {
  position: relative;
  display: inline-block;
  width: 100%;
  max-width: none;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
  line-height: 0;
}

.stage img {
  display: block;
  width: 100%;
  max-width: none;
  max-height: none;
  height: auto;
  border: 1px solid #edf0ee;
  border-radius: var(--radius);
  background: #fff;
}

#inkCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  touch-action: none;
}

.answerFrame {
  overflow: hidden;
  width: 100%;
  border: 1px solid #dfe6e2;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
}

.answerHeader {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  min-height: 44px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  line-height: 1.3;
}

.answerHeader strong {
  font-size: 16px;
}

.answerHeader span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.answerPad {
  position: relative;
  height: var(--answer-height);
  background:
    linear-gradient(#eef2ef 1px, transparent 1px) 0 0 / 100% 44px,
    #fff;
}

#answerCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  touch-action: none;
}

.app.is-inking #inkCanvas,
.app.is-inking #answerCanvas {
  cursor: crosshair;
  pointer-events: auto;
}

.app.is-presentation {
  grid-template-columns: 0 minmax(0, 1fr);
}

.app.is-presentation .sidebar {
  display: none;
}

.app.is-presentation .toolbar {
  min-height: 58px;
  padding: 8px 12px;
}

.app.is-presentation .stage {
  padding: 12px;
}

.app.is-presentation .stage__inner {
  min-height: calc(100vh - 140px);
}

.app.is-presentation .stage img {
  max-height: none;
}

@media (max-width: 920px) {
  .app {
    grid-template-columns: 1fr;
    width: 100vw;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .sidebar {
    width: 100vw;
    max-width: 100vw;
    min-width: 0;
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .main,
  .toolbar,
  .inkbar {
    width: 100vw;
    max-width: 100vw;
    min-width: 0;
  }

  .selector {
    width: calc(100vw - 36px);
    max-width: calc(100vw - 36px);
  }

  .brand,
  .modeTabs,
  .jumpBox {
    max-width: calc(100vw - 36px);
  }

  .selector {
    max-height: 188px;
  }

  .toolbar {
    position: sticky;
    top: 0;
    z-index: 3;
    display: grid;
    grid-template-columns: 42px minmax(0, calc(100vw - 180px)) 42px 42px;
    align-items: center;
  }

  .toolbar__spacer {
    display: none;
  }

  .titleBlock {
    grid-column: 2 / 4;
    grid-row: 1;
  }

  #prevBtn {
    grid-column: 1;
    grid-row: 1;
  }

  #nextBtn {
    grid-column: 4;
    grid-row: 1;
  }

  #taughtBtn {
    grid-column: 1;
    grid-row: 2;
  }

  .zoomGroup {
    grid-column: 2;
    grid-row: 2;
    justify-self: stretch;
  }

  #presentationBtn {
    grid-column: 3;
    grid-row: 2;
  }

  #fullscreenBtn {
    grid-column: 4;
    grid-row: 2;
  }

  .stage {
    padding: 12px;
  }

  .inkbar {
    padding: 10px 12px;
  }

  .stage__inner {
    min-height: calc(100vh - 174px);
  }

  .stage img {
    max-height: none;
  }
}

@media (max-width: 560px) {
  .toolbar {
    grid-template-columns: 42px minmax(0, calc(100vw - 128px)) 42px;
  }

  .selector {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .titleBlock {
    grid-column: 2;
  }

  #nextBtn {
    grid-column: 3;
  }

  #presentationBtn {
    display: none;
  }

  #fullscreenBtn {
    grid-column: 3;
    grid-row: 2;
  }

  .titleBlock h2 {
    font-size: 17px;
  }

  .toolButton span {
    display: none;
  }

  .inkbar .toolButton span,
  .sizeControl span {
    display: inline;
  }

  .inkbar .toolButton {
    min-width: 42px;
    padding: 0 10px;
  }

  .zoomReadout {
    min-width: 48px;
  }

  .answerHeader {
    display: block;
  }

  .answerHeader span {
    display: block;
    margin-top: 3px;
  }
}
