/* KG Portal V11.2 R11.1 — unified exercise themes and iPhone web layout. */

html[data-kg-theme="dark"] .v11ExercisePage {
  --v11-bg: #0a1018;
  --v11-panel: #111a27;
  --v11-elevated: #172231;
  --v11-input: #0d151f;
  --v11-text: #f4f3ef;
  --v11-muted: #aab3be;
  --v11-border: #2d3b4d;
  --v11-border-strong: #475a70;
  --v11-accent: #f0eadf;
  --v11-accent-text: #16191d;
  --v11-success: #49d89a;
  --v11-warning: #f2bf62;
  --v11-danger: #ff7b82;
  --v11-shadow: 0 28px 80px rgb(0 0 0 / 42%);
  color-scheme: dark;
}

.v11SourceContextControl {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
}

.v11SourceContextControl > button {
  min-width: 76px;
  border: 1px solid var(--kg-border-strong, rgba(126, 112, 91, 0.38));
  border-radius: 10px;
  padding: 0 12px;
  background: var(--kg-surface-raised, #f2ede4);
  color: inherit;
  font-weight: 700;
  cursor: pointer;
}

.v11SourceContextControl > button:hover:not(:disabled) {
  border-color: var(--kg-accent, #c7684e);
  color: var(--kg-accent, #c7684e);
}

@media (max-width: 760px) {
  .v11SourceContextControl {
    grid-template-columns: minmax(0, 1fr) 82px;
  }
}

html[data-kg-theme="light"] .v11ExercisePage {
  --v11-bg: #f3f0e9;
  --v11-panel: #ffffff;
  --v11-elevated: #f8f5ef;
  --v11-input: #fffefb;
  --v11-text: #191b1e;
  --v11-muted: #656c74;
  --v11-border: #d8d2c8;
  --v11-border-strong: #aaa398;
  --v11-accent: #1a1b1e;
  --v11-accent-text: #ffffff;
  --v11-success: #16734e;
  --v11-warning: #916317;
  --v11-danger: #b52e38;
  --v11-shadow: 0 24px 68px rgb(45 38 28 / 16%);
  color-scheme: light;
}

html[data-kg-theme] .v11ExercisePage {
  min-width: 0;
  color: var(--v11-text);
}

html[data-kg-theme] .v11ExercisePage :where(button, input, select, textarea, a) {
  font: inherit;
}

html[data-kg-theme] .v11ExercisePage :where(
  .v11PageHeader,
  .v11HeaderDrive,
  .v11Tabs,
  .v11ExerciseForm,
  .v11SourcePanel,
  .v11FormResult,
  .v11StatGrid > div,
  .v11ExerciseCard,
  .v11DriveSetupCard,
  .v11EditorCard,
  .v11DetailCard
) {
  color: var(--v11-text);
  border-color: var(--v11-border);
  background: var(--v11-panel);
}

html[data-kg-theme] .v11ExercisePage :where(
  .v11PageHeader p,
  .v11HeaderDrive small,
  .v11FormIntro p,
  .v11SectionHead p,
  .v11CardBody p,
  .v11EnglishName,
  .v11GifUploader small,
  .v11DetailHead p,
  .v11SourceTable small,
  .v11HistoryList small,
  .v11HistoryList span,
  .v11DetailEmpty
) {
  color: var(--v11-muted);
}

html[data-kg-theme] .v11ExercisePage :where(input, select, textarea) {
  min-width: 0;
  color: var(--v11-text);
  border: 1px solid var(--v11-border);
  background: var(--v11-input);
  outline: none;
}

html[data-kg-theme] .v11ExercisePage :where(input, select, textarea):focus {
  border-color: var(--v11-border-strong);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--v11-border-strong) 24%, transparent);
}

html[data-kg-theme] .v11ExercisePage :where(button, .v11DetailActions a, .v11SourceTable a) {
  min-height: 40px;
  color: var(--v11-text);
  border-color: var(--v11-border);
  background: var(--v11-elevated);
}

html[data-kg-theme] .v11ExercisePage :where(button[data-primary="true"], .v11FormFooter button, .v11ActionRow > button, .v11GifActions button) {
  color: var(--v11-accent-text);
  border-color: var(--v11-accent);
  background: var(--v11-accent);
}

html[data-kg-theme] .v11ExercisePage button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

html[data-kg-theme] .v11ExercisePage .v11ExerciseCard {
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 12px 32px rgb(0 0 0 / 8%);
}

html[data-kg-theme] .v11ExercisePage .v11ExerciseCard:focus-visible {
  outline: 3px solid var(--v11-border-strong);
  outline-offset: 3px;
}

html[data-kg-theme] .v11ExercisePage :where(.v11Preview, .v11EmptyPreview) {
  color: var(--v11-muted);
  border-color: var(--v11-border);
  background: var(--v11-elevated);
}

html[data-kg-theme] .v11ExercisePage :where(.v11FileDrop, .v11GifDrop) {
  color: var(--v11-text);
  border-color: var(--v11-border-strong);
  background: var(--v11-elevated);
}

html[data-kg-theme] .v11ExercisePage :where(.v11TagOptions button, .v11CardTags span) {
  color: var(--v11-muted);
  border-color: var(--v11-border);
  background: var(--v11-elevated);
}

html[data-kg-theme] .v11ExercisePage .v11TagOptions button.selected {
  color: var(--v11-accent-text);
  border-color: var(--v11-accent);
  background: var(--v11-accent);
}

html[data-kg-theme] .v11ExercisePage .v11Notice.success {
  color: var(--v11-success);
  border-color: color-mix(in srgb, var(--v11-success) 52%, var(--v11-border));
  background: color-mix(in srgb, var(--v11-success) 9%, var(--v11-panel));
}

html[data-kg-theme] .v11ExercisePage .v11Notice.error {
  color: var(--v11-danger);
  border-color: color-mix(in srgb, var(--v11-danger) 52%, var(--v11-border));
  background: color-mix(in srgb, var(--v11-danger) 9%, var(--v11-panel));
}

html[data-kg-theme] .v11ExercisePage :where(.v11EditorBackdrop, .v11DetailBackdrop, .v11DriveSetupBackdrop) {
  overscroll-behavior: contain;
  background: rgb(3 7 12 / 72%);
  backdrop-filter: blur(12px);
}

.v11DetailBackdrop {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: 24px;
}

.v11DetailCard {
  width: min(1320px, 100%);
  max-height: min(900px, calc(100dvh - 48px));
  overflow: hidden;
  border: 1px solid var(--v11-border);
  border-radius: 22px;
  box-shadow: var(--v11-shadow);
}

.v11DetailHead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 26px;
  border-bottom: 1px solid var(--v11-border);
  background: var(--v11-panel);
}

.v11DetailHead h2 {
  margin: 7px 0 5px;
  color: var(--v11-text);
  font-size: clamp(25px, 3vw, 38px);
  line-height: 1.08;
}

.v11DetailHead p {
  margin: 0;
  line-height: 1.55;
}

.v11DetailHead > button {
  flex: 0 0 auto;
  width: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid var(--v11-border);
  border-radius: 12px;
  font-size: 22px;
}

.v11DetailBody {
  max-height: calc(min(900px, 100dvh - 48px) - 128px);
  overflow: auto;
  padding: 22px 26px 30px;
  background: var(--v11-bg);
}

.v11DetailActions,
.v11DetailActions > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.v11DetailActions {
  margin-bottom: 20px;
}

.v11DetailActions :where(a, button) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 9px 14px;
  border: 1px solid var(--v11-border);
  border-radius: 10px;
  color: var(--v11-text);
  text-decoration: none;
}

.v11DetailSection {
  overflow: hidden;
  margin-top: 16px;
  border: 1px solid var(--v11-border);
  border-radius: 16px;
  background: var(--v11-panel);
}

.v11DetailSectionHead {
  display: flex;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--v11-border);
}

.v11DetailSectionHead h3 {
  margin: 5px 0 0;
  color: var(--v11-text);
  font-size: 20px;
}

.v11SourceTableWrap {
  overflow-x: auto;
}

.v11SourceTable {
  width: 100%;
  min-width: 1060px;
  border-collapse: collapse;
  color: var(--v11-text);
}

.v11SourceTable th,
.v11SourceTable td {
  padding: 14px 15px;
  border-bottom: 1px solid var(--v11-border);
  text-align: left;
  vertical-align: top;
}

.v11SourceTable th {
  color: var(--v11-muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--v11-elevated);
}

.v11SourceTable td:first-child {
  width: 270px;
}

.v11SourceTable td :where(b, small, .v11Badge) {
  display: block;
  max-width: 280px;
}

.v11SourceTable td small {
  overflow: hidden;
  margin: 4px 0 8px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.v11SourceTable a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--v11-border);
  border-radius: 9px;
  color: var(--v11-text);
  text-decoration: none;
}

.v11DetailEmpty {
  padding: 28px 20px;
  text-align: center;
}

.v11HistoryToggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border: 0;
  border-radius: 0;
  text-align: left;
}

.v11HistoryToggle > span:first-child :where(b, small) {
  display: block;
}

.v11HistoryList {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0 20px 16px;
  list-style: none;
}

.v11HistoryList li {
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 12px;
  padding: 14px 0;
  border-top: 1px solid var(--v11-border);
}

.v11HistoryList i {
  width: 8px;
  height: 8px;
  margin-top: 6px;
  border-radius: 999px;
  background: var(--v11-border-strong);
}

.v11HistoryList div :where(b, span, small) {
  display: block;
  line-height: 1.5;
}

html[data-kg-theme] .v11ExercisePage .v11EditorCard {
  box-shadow: var(--v11-shadow);
}

html[data-kg-theme] .v11ExercisePage :where(.v11EditorHead, .v11EditorActions) {
  color: var(--v11-text);
  border-color: var(--v11-border);
  background: var(--v11-panel);
}

html[data-kg-theme] .v11ExercisePage :where(.v11EditorBody, .v11EditorPreview) {
  color: var(--v11-text);
  border-color: var(--v11-border);
  background: var(--v11-bg);
}

@media (max-width: 760px) {
  html[data-kg-theme] .v11ExercisePage {
    width: 100%;
    max-width: 100%;
    overflow-x: clip;
    padding: 10px 10px calc(24px + env(safe-area-inset-bottom));
  }

  html[data-kg-theme] .v11ExercisePage :where(button, a, input, select, textarea) {
    touch-action: manipulation;
  }

  html[data-kg-theme] .v11ExercisePage :where(input, select, textarea) {
    min-height: 46px;
    font-size: 16px;
  }

  html[data-kg-theme] .v11ExercisePage textarea {
    min-height: 128px;
  }

  html[data-kg-theme] .v11ExercisePage :where(button, .v11DetailActions a, .v11SourceTable a) {
    min-height: 44px;
  }

  html[data-kg-theme] .v11ExercisePage .v11PageHeader {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    padding: 18px 16px;
    border-radius: 16px;
  }

  html[data-kg-theme] .v11ExercisePage .v11PageHeader h1 {
    font-size: clamp(31px, 10vw, 44px);
  }

  html[data-kg-theme] .v11ExercisePage .v11HeaderDrive {
    width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: 12px minmax(0, 1fr);
    padding: 13px;
  }

  html[data-kg-theme] .v11ExercisePage .v11DriveActions {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  html[data-kg-theme] .v11ExercisePage .v11Tabs {
    position: sticky;
    top: 6px;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 6px;
    border-radius: 14px;
    box-shadow: 0 8px 24px rgb(0 0 0 / 12%);
  }

  html[data-kg-theme] .v11ExercisePage .v11Tabs button {
    width: 100%;
    justify-content: center;
    padding: 10px 8px;
    white-space: normal;
  }

  html[data-kg-theme] .v11ExercisePage :where(.v11StatGrid, .v11CardGrid, .v11Fields.two, .v11Fields.three, .v11TagColumns, .v11SourceGrid) {
    grid-template-columns: minmax(0, 1fr);
  }

  html[data-kg-theme] .v11ExercisePage .v11StatGrid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  html[data-kg-theme] .v11ExercisePage .v11StatGrid > div {
    min-width: 0;
    padding: 14px;
  }

  html[data-kg-theme] .v11ExercisePage .v11LibraryToolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  html[data-kg-theme] .v11ExercisePage .v11Search {
    width: 100%;
    min-width: 0;
  }

  html[data-kg-theme] .v11ExercisePage .v11ExerciseCard {
    width: 100%;
    min-width: 0;
    border-radius: 16px;
  }

  html[data-kg-theme] .v11ExercisePage .v11CardButtons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  html[data-kg-theme] .v11ExercisePage .v11CardButtons button {
    width: 100%;
  }

  html[data-kg-theme] .v11ExercisePage :where(.v11SourcePanel, .v11ExerciseForm, .v11FormResult) {
    padding: 16px;
    border-radius: 16px;
  }

  html[data-kg-theme] .v11ExercisePage :where(.v11FileDrop, .v11GifDrop) {
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 10px;
    padding: 12px;
  }

  html[data-kg-theme] .v11ExercisePage :where(.v11FormFooter, .v11ActionRow, .v11GifActions) {
    align-items: stretch;
    flex-direction: column;
  }

  html[data-kg-theme] .v11ExercisePage :where(.v11FormFooter button, .v11ActionRow > button, .v11GifActions button) {
    width: 100%;
  }

  html[data-kg-theme] .v11ExercisePage :where(.v11EditorBackdrop, .v11DetailBackdrop, .v11DriveSetupBackdrop) {
    place-items: stretch;
    padding: 0;
  }

  html[data-kg-theme] .v11ExercisePage :where(.v11EditorCard, .v11DetailCard, .v11DriveSetupCard) {
    width: 100%;
    max-width: none;
    height: 100dvh;
    max-height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  html[data-kg-theme] .v11ExercisePage :where(.v11EditorHead, .v11DetailHead, .v11DriveSetupHead) {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: calc(14px + env(safe-area-inset-top)) 14px 14px;
  }

  html[data-kg-theme] .v11ExercisePage :where(.v11EditorHead h2, .v11DetailHead h2, .v11DriveSetupHead h2) {
    font-size: 25px;
  }

  html[data-kg-theme] .v11ExercisePage .v11EditorBody {
    height: calc(100dvh - 106px);
    display: block;
    overflow-y: auto;
    padding: 0;
  }

  html[data-kg-theme] .v11ExercisePage .v11EditorPreview {
    position: static;
    padding: 14px;
    border: 0;
    border-bottom: 1px solid var(--v11-border);
  }

  html[data-kg-theme] .v11ExercisePage .v11EditorForm {
    padding: 16px 14px calc(94px + env(safe-area-inset-bottom));
  }

  html[data-kg-theme] .v11ExercisePage .v11EditorActions {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 8;
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--v11-border);
    box-shadow: 0 -12px 30px rgb(0 0 0 / 18%);
  }

  html[data-kg-theme] .v11ExercisePage .v11EditorActions button {
    width: 100%;
    min-width: 0;
  }

  .v11DetailHead {
    gap: 10px;
  }

  .v11DetailHead p {
    font-size: 12px;
  }

  .v11DetailBody {
    height: calc(100dvh - 112px);
    max-height: none;
    padding: 14px 12px calc(28px + env(safe-area-inset-bottom));
  }

  .v11DetailActions,
  .v11DetailActions > div {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
    width: 100%;
  }

  .v11DetailActions :where(a, button) {
    width: 100%;
  }

  .v11SourceTableWrap {
    overflow: visible;
  }

  .v11SourceTable,
  .v11SourceTable tbody,
  .v11SourceTable tr,
  .v11SourceTable td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .v11SourceTable thead {
    display: none;
  }

  .v11SourceTable tr {
    padding: 8px 12px;
    border-bottom: 1px solid var(--v11-border);
  }

  .v11SourceTable td,
  .v11SourceTable td:first-child {
    width: 100%;
    display: grid;
    grid-template-columns: 102px minmax(0, 1fr);
    gap: 10px;
    padding: 9px 0;
    border: 0;
  }

  .v11SourceTable td::before {
    content: attr(data-label);
    color: var(--v11-muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  .v11SourceTable td :where(b, small, .v11Badge) {
    grid-column: 2;
    max-width: 100%;
  }

  .v11SourceTable td small {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .v11HistoryToggle {
    min-height: 64px;
    padding: 12px;
  }

  .v11HistoryList {
    padding: 0 12px 12px;
  }
}

@media (max-width: 390px) {
  html[data-kg-theme] .v11ExercisePage .v11StatGrid {
    grid-template-columns: minmax(0, 1fr);
  }

  html[data-kg-theme] .v11ExercisePage .v11CardFooter {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  html[data-kg-theme] .v11ExercisePage *,
  html[data-kg-theme] .v11ExercisePage *::before,
  html[data-kg-theme] .v11ExercisePage *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
  }
}
