:root {
  --ink: #1d252c;
  --muted: #66707a;
  --line: #d7dde3;
  --panel: #f5f7f9;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --paper: #ffffff;
  --shadow: 0 18px 45px rgba(31, 41, 55, 0.15);
  --page-width: 816px;
  --page-min-height: 1056px;
  --page-padding-y: 82px;
  --page-padding-x: 76px;
  --page-zoom: 1;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: #dfe5ea;
  font-family: Arial, Helvetica, sans-serif;
}

button,
select,
input {
  font: inherit;
}

button,
select,
input[type="color"] {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

button {
  min-width: 38px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  padding: 0 9px;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
  transition: border-color 120ms ease, background-color 120ms ease, color 120ms ease;
}

button:hover,
button.active {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: #e8f5f3;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 22px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

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

.mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.document-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

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

.toolbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.ribbon-tabs {
  display: flex;
  gap: 2px;
  padding: 6px 14px 0;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.tab-button {
  height: 32px;
  border-bottom-color: transparent;
  border-radius: 6px 6px 0 0;
  background: #fff;
}

.tab-button.active {
  background: var(--panel);
  border-color: var(--line);
  border-bottom-color: var(--panel);
  color: var(--accent-strong);
}

.ribbon-panel {
  display: none;
  min-height: 92px;
  gap: 12px;
  align-items: stretch;
  padding: 10px 14px;
}

.ribbon-panel.active {
  display: flex;
}

.tool-group {
  display: flex;
  gap: 8px;
  align-items: end;
  padding: 0 12px 0 0;
  border-right: 1px solid var(--line);
}

.tool-group:last-child {
  border-right: 0;
}

.tool-group.wide {
  min-width: 480px;
  display: grid;
  grid-template-columns: 1.1fr 1.3fr 0.7fr 1.1fr;
}

.tool-group.compact {
  flex-wrap: wrap;
  align-content: flex-start;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

select {
  width: 100%;
  height: 36px;
  border-radius: 6px;
  padding: 0 10px;
}

input[type="text"] {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
}

.color-control {
  grid-template-columns: 1fr auto;
  align-items: center;
}

input[type="color"] {
  width: 42px;
  height: 34px;
  padding: 3px;
  border-radius: 6px;
}

.document-panel {
  min-width: 0;
  overflow: auto;
  padding: 26px 22px 42px;
  background: #dfe5ea;
}

.document-panel.hide-ruler .ruler {
  display: none;
}

.ruler {
  width: min(var(--page-width), 100%);
  height: 24px;
  margin: 0 auto 12px;
  border: 1px solid var(--line);
  background:
    repeating-linear-gradient(90deg, transparent 0 31px, #c5ccd4 31px 32px),
    #f7f8fa;
  transform: scale(var(--page-zoom));
  transform-origin: top center;
}

.page {
  width: min(var(--page-width), 100%);
  min-height: var(--page-min-height);
  margin: 0 auto;
  padding: var(--page-padding-y) var(--page-padding-x);
  background: var(--paper);
  box-shadow: var(--shadow);
  outline: none;
  line-height: 1.55;
  font-size: 16px;
  column-count: var(--page-columns, 1);
  column-gap: 42px;
  transform: scale(var(--page-zoom));
  transform-origin: top center;
}

.page:focus {
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.2), var(--shadow);
}

.page h1,
.page h2,
.page h3 {
  line-height: 1.2;
  margin: 0 0 14px;
}

.page h1 {
  font-size: 30px;
}

.page h2 {
  font-size: 24px;
}

.page h3 {
  font-size: 19px;
}

.page p {
  margin: 0 0 12px;
}

.page blockquote {
  margin: 16px 0;
  padding: 4px 0 4px 16px;
  border-left: 4px solid var(--accent);
  color: #3f4b55;
}

.page a {
  color: var(--accent-strong);
}

.page table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
}

.page td,
.page th {
  min-width: 80px;
  padding: 8px;
  border: 1px solid #9aa4af;
}

.page img {
  max-width: 100%;
  height: auto;
}

.page .page-break {
  break-after: page;
  border-top: 2px dashed #b8c0c8;
  margin: 24px 0;
  height: 1px;
}

.page .text-box {
  display: inline-block;
  min-width: 180px;
  min-height: 70px;
  padding: 10px;
  margin: 8px 0;
  border: 1px solid #6b7280;
  background: #f8fafc;
}

.page .comment-mark {
  background: #fff2a8;
  border-bottom: 2px solid #f59e0b;
}

.focus-mode .topbar,
.focus-mode .toolbar,
.focus-mode .statusbar {
  display: none;
}

.statusbar {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 8px 22px;
  background: #fff;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 900px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px;
  }

  .ribbon-panel.active {
    min-width: 980px;
  }

  .document-panel {
    padding: 14px 10px 30px;
  }

  .page {
    min-height: 760px;
    padding: 42px 26px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .topbar,
  .toolbar,
  .statusbar,
  .ruler {
    display: none;
  }

  .workspace {
    display: block;
  }

  .document-panel {
    padding: 0;
    overflow: visible;
    background: #fff;
  }

  .page {
    width: auto;
    min-height: 0;
    padding: 0;
    box-shadow: none;
    transform: none;
  }
}
