:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  background: #f4f6f8;
  color: #18202a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

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

.viewer {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  background: #e8edf2;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid #d2d9e2;
  background: #ffffff;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid #c7d0dc;
  border-radius: 6px;
  background: #ffffff;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

select,
input,
textarea {
  border: 1px solid #c7d0dc;
  border-radius: 6px;
  background: #ffffff;
  color: #18202a;
}

select,
input {
  height: 36px;
  padding: 0 10px;
}

.problem-frame {
  display: grid;
  align-items: start;
  justify-items: center;
  overflow: auto;
  padding: 24px;
}

.problem-frame img {
  display: block;
  width: min(100%, 620px);
  aspect-ratio: 435 / 395;
  object-fit: cover;
  object-position: top;
  margin: 0 auto;
  background: #ffffff;
  box-shadow: 0 10px 32px rgba(24, 32, 42, 0.14);
}

.problem-frame.show-hint img {
  aspect-ratio: auto;
  object-fit: initial;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
  border-left: 1px solid #d2d9e2;
  background: #ffffff;
}

.problem-control label,
.notes label {
  display: block;
  margin-bottom: 8px;
  color: #526070;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.problem-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.problem-row input {
  width: 100%;
}

button {
  height: 36px;
  padding: 0 12px;
  border: 1px solid #b8c4d2;
  border-radius: 6px;
  background: #f8fafc;
  cursor: pointer;
  font-weight: 700;
}

button.active {
  border-color: #147d64;
  background: #e4f4ef;
  color: #0e604c;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.actions button:first-child {
  grid-column: 1 / -1;
  background: #17202a;
  color: #ffffff;
}

.status {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid #d7dee8;
  border-radius: 8px;
  overflow: hidden;
}

.status button {
  padding: 14px;
  height: auto;
  border: 0;
  border-radius: 0;
  background: #ffffff;
  text-align: left;
  cursor: pointer;
  font-weight: 700;
}

.status button + button {
  border-left: 1px solid #d7dee8;
}

.status button:hover {
  background: #f4f7fb;
}

.status strong {
  display: block;
  font-size: 24px;
}

.status span {
  display: block;
  color: #526070;
  font-size: 13px;
  font-weight: 400;
}

.solution {
  padding: 14px;
  border: 1px solid #d7dee8;
  border-radius: 8px;
  background: #fbfcfe;
}

.solution-title {
  margin-bottom: 8px;
  color: #526070;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.solution p {
  margin: 0;
  line-height: 1.55;
  white-space: pre-wrap;
}

.solution-images {
  display: grid;
  gap: 8px;
}

.solution-images img {
  display: block;
  width: 100%;
  border: 1px solid #d7dee8;
  background: #ffffff;
  cursor: zoom-in;
}

.solution details img {
  cursor: zoom-in;
}

.lightbox {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 12, 18, 0.88);
  cursor: zoom-out;
  z-index: 1000;
}

.lightbox[hidden] {
  display: none;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  background: #ffffff;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}

.solution details {
  margin-top: 14px;
}

.solution summary {
  cursor: pointer;
  color: #526070;
  font-weight: 800;
}

.solution details img {
  display: block;
  width: 100%;
  max-height: 520px;
  margin-top: 10px;
  border: 1px solid #d7dee8;
  object-fit: contain;
  object-position: top;
}

.notes textarea {
  width: 100%;
  resize: vertical;
  padding: 10px;
  line-height: 1.45;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 12, 18, 0.55);
}

.modal-content {
  position: relative;
  width: min(720px, 100%);
  max-height: min(85vh, 720px);
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-radius: 10px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #e3e8ef;
}

.modal-header h2 {
  margin: 0;
  font-size: 16px;
}

.modal-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1 1 auto;
}

.modal-list.grid-mode {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.modal-chapter h3 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #526070;
}

.problem-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 4px;
}

.problem-box {
  display: grid;
  place-items: center;
  height: 36px;
  padding: 0;
  border: 1px solid #d7dee8;
  border-radius: 4px;
  background: #f6f8fb;
  color: #18202a;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.problem-box:hover {
  background: #e8eef5;
}

.problem-box.solved {
  background: #c9ecd9;
  border-color: #69b894;
  color: #0e604c;
}

.problem-box.review {
  border-color: #d6a83a;
  border-width: 2px;
  height: 36px;
}

.problem-box.solved.review {
  background: #c9ecd9;
}

.problem-box.current {
  box-shadow: 0 0 0 2px #18202a;
}

@media (max-width: 480px) {
  .modal-content {
    max-height: 90vh;
  }
  .problem-grid {
    grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  }
  .problem-box {
    height: 32px;
    font-size: 11px;
  }
}

.chapter-control {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chapter-control label {
  color: #526070;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.chapter-control select {
  width: 100%;
}

.problem-control {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.actions .ghost {
  background: #f1f4f8;
  color: #18202a;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }

  .panel {
    gap: 12px;
    padding: 14px;
    border-left: 0;
    border-top: 1px solid #d2d9e2;
  }

  .problem-frame {
    padding: 12px;
  }

  .problem-frame img {
    width: 100%;
    max-width: none;
  }

  .toolbar {
    padding: 10px 12px;
  }

  .status div {
    padding: 10px;
  }

  .status strong {
    font-size: 20px;
  }
}

@media (max-width: 480px) {
  .problem-frame {
    padding: 8px;
  }

  .panel {
    padding: 12px;
  }

  .actions {
    grid-template-columns: 1fr;
  }

  .actions button:first-child {
    grid-column: auto;
  }

  .notes textarea {
    min-height: 120px;
  }
}
