:root {
  color-scheme: light;
  --page: #f6f8fb;
  --toolbar: #ffffff;
  --toolbar-border: #b8becf;
  --stage: #d7dcff;
  --text: #0d1222;
  --muted: #47506a;
  --accent: #2457ff;
  --focus: #111827;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--page);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

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

.toolbar {
  display: flex;
  justify-content: center;
  align-items: stretch;
  gap: 0;
  min-height: 76px;
  padding: 20px clamp(8px, 3vw, 24px) 0;
  background: var(--toolbar);
  border-top: 1px solid #7ba27e;
  z-index: 4;
}

.toolbar select,
.toolbar button {
  min-height: 56px;
  border: 1px solid #767b86;
  border-radius: 3px;
  background: #ffffff;
  color: #000000;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(20px, 2.25vw, 40px);
  line-height: 1;
}

.toolbar select {
  min-width: min(28vw, 450px);
  padding: 0 36px 0 8px;
}

.toolbar select:first-child {
  min-width: min(12vw, 210px);
}

.toolbar select:nth-child(2) {
  min-width: min(24vw, 450px);
}

.toolbar button {
  padding: 0 14px;
  cursor: pointer;
}

.toolbar button.active {
  background: #e8f0ff;
  box-shadow: inset 0 0 0 2px #2457ff;
}

.toolbar button:hover,
.toolbar select:hover {
  background: #f3f4f8;
}

.toolbar button:focus-visible,
.toolbar select:focus-visible,
.builder-actions button:focus-visible,
.grid-cell:focus-visible,
.progress-strip input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 36vw) minmax(0, 1fr);
  min-height: 0;
}

.builder-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #ffffff;
  border-right: 1px solid #b8becf;
}

.builder-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  padding: 12px 0 8px;
}

.builder-actions button {
  min-height: 34px;
  border: 1px solid #8b909b;
  border-radius: 3px;
  background: #f7f7f7;
  color: #000000;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(16px, 1.5vw, 21px);
  line-height: 1;
  cursor: pointer;
}

.builder-actions button:disabled {
  cursor: not-allowed;
  color: #8b909b;
  background: #eceff4;
}

.builder-progress {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid #d8dce7;
  color: #000000;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(17px, 1.65vw, 23px);
}

.grid-builder {
  align-self: start;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  width: 100%;
  aspect-ratio: 1;
  border-top: 1px solid #202020;
  border-left: 1px solid #202020;
}

.grid-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-right: 1px solid #202020;
  border-bottom: 1px solid #202020;
  background: #ffffff;
  color: #000000;
  font-family: Arial, Helvetica, sans-serif;
  font-size: clamp(36px, 5vw, 68px);
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

.grid-cell:hover {
  background: #eef3ff;
}

.grid-cell.selected {
  background: var(--face-color, #2457ff);
  color: var(--face-text, #ffffff);
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.65);
}

.grid-cell.valid {
  background: var(--face-color, #08a967);
  color: var(--face-text, #ffffff);
}

.grid-cell.invalid {
  background: #ff4e6a;
  color: #ffffff;
}

.builder-message {
  min-height: 64px;
  padding: 10px 14px;
  border-top: 1px solid #d8dce7;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.28;
}

.builder-message.valid {
  color: #075f3f;
  background: #e8f9f0;
}

.builder-message.invalid {
  color: #842034;
  background: #fff0f2;
}

.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: var(--stage);
}

#sceneCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.pattern-label {
  position: absolute;
  top: clamp(14px, 2vw, 30px);
  left: 50%;
  width: min(92%, 920px);
  transform: translateX(-50%);
  color: rgba(0, 0, 0, 0.82);
  font-family: Arial, Helvetica, sans-serif;
  font-size: clamp(22px, 3vw, 54px);
  font-style: italic;
  line-height: 1.05;
  text-align: center;
  text-shadow: 0 1px 4px rgba(255, 255, 255, 0.62);
  pointer-events: none;
  user-select: none;
}

.progress-strip {
  position: absolute;
  right: clamp(12px, 3vw, 28px);
  bottom: clamp(12px, 3vw, 24px);
  display: grid;
  grid-template-columns: minmax(160px, 280px) 52px;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid rgba(36, 45, 84, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 12px 28px rgba(42, 52, 106, 0.14);
  color: var(--muted);
  font-size: 15px;
  backdrop-filter: blur(10px);
}

.progress-strip input {
  width: 100%;
  accent-color: var(--accent);
}

.progress-strip output {
  min-width: 48px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.discovery-status {
  position: absolute;
  left: clamp(12px, 3vw, 28px);
  bottom: clamp(58px, 7vw, 74px);
  max-width: min(420px, calc(100vw - 44px));
  padding: 10px 14px;
  border: 1px solid rgba(36, 45, 84, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 12px 28px rgba(42, 52, 106, 0.14);
  color: var(--muted);
  font-size: 15px;
  line-height: 1.25;
  pointer-events: none;
  backdrop-filter: blur(10px);
}

.xapi-score {
  display: none;
  position: absolute;
  left: clamp(12px, 3vw, 28px);
  bottom: clamp(12px, 3vw, 24px);
  max-width: min(420px, calc(100vw - 44px));
  padding: 8px 12px;
  border: 1px solid rgba(36, 45, 84, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 10px 22px rgba(42, 52, 106, 0.12);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.2;
  pointer-events: none;
  backdrop-filter: blur(10px);
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  .app-shell {
    min-height: 100vh;
    height: auto;
  }

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

  .builder-panel {
    border-right: 0;
    border-bottom: 1px solid #b8becf;
    overflow: visible;
  }

  .builder-actions {
    padding: 8px 8px 6px;
    gap: 6px;
  }

  .builder-actions button {
    min-height: 42px;
    font-size: 19px;
  }

  .builder-progress {
    min-height: 36px;
    font-size: 18px;
  }

  .grid-builder {
    width: min(100vw, 520px);
    margin: 0 auto;
  }

  .grid-cell {
    font-size: clamp(28px, 11vw, 56px);
  }

  .builder-message {
    min-height: 52px;
    font-size: 14px;
  }

  .toolbar {
    flex-wrap: wrap;
    justify-content: stretch;
    gap: 6px;
    min-height: 0;
    padding: 8px;
  }

  .toolbar select,
  .toolbar button,
  .toolbar select:first-child,
  .toolbar select:nth-child(2) {
    flex: 1 1 150px;
    min-width: 0;
    min-height: 46px;
    font-size: 24px;
  }

  .stage {
    height: calc(100vh - 124px);
    min-height: 480px;
  }

  .progress-strip {
    left: 12px;
    right: 12px;
    bottom: 12px;
    grid-template-columns: 1fr 48px;
  }

  .discovery-status {
    left: 12px;
    right: 12px;
    bottom: 104px;
    max-width: none;
    font-size: 14px;
  }

  .xapi-score {
    left: 12px;
    right: 12px;
    bottom: 70px;
    max-width: none;
    font-size: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .progress-strip {
    backdrop-filter: none;
  }

  .discovery-status {
    backdrop-filter: none;
  }

  .xapi-score {
    backdrop-filter: none;
  }
}
