/* Libertinus Math local font */
@font-face {
  font-family: 'Libertinus Math';
  src: url('../fonts/LibertinusMath-Regular.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

.instructions-row {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

#instructions-text {
  font-size: 1.1rem;
  font-weight: 500;
  color: #38718e;
  margin-right: 1.2rem;
  min-width: 90px;
  text-align: left;
  display: inline-block;
  margin: 10px;
}

body { 
  font-family: sans-serif; 
  margin: 0; 
  display: flex; 
  flex-direction: column; 
  height: 100vh; 
  height: 100dvh; /* Dynamic viewport height for mobile */
  /* iOS Safari fixes */
  -webkit-overflow-scrolling: touch;
  overflow: hidden;
  position: fixed;
  width: 100%;
  top: 0;
  left: 0;
  user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  -moz-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#workspace { 
  flex: 1; 
  display: flex; 
  flex-direction: column; 
  position: relative;
  /* iOS Safari fixes */
  overflow: hidden;
  touch-action: none;
  /* Ensure proper height calculation */
  min-height: 0;
}

#problem-area {
  padding: 0;
  background: #f0f0f0;
  text-align: center;
  border-bottom: 1px solid #ccc;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  margin-bottom: 5px;
}

/* Top header styles */
#top-header {
  display: flex;
  align-items: center;
  background: #222;
  color: #fff;
  padding: 0;
  font-size: 1.4rem;
  font-weight: bold;
  letter-spacing: 1px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.04);
}

#top-hamburger {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.4rem;
  margin-right: 0.75rem;
  cursor: pointer;
}

#app-title {
  font-size: 1.4rem;
  font-weight: bold;
  letter-spacing: 1px;
}

.equation-row {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  gap: 1rem;
  margin-bottom: 10px;
}

#equation {
  font-size: 1.5rem;
  font-weight: bold;
  margin-right: 0;
  padding: 8px 15px;
  border: 1px solid #ccc;
  background: #ffffff;
  border-radius: 8px;
  font-family: 'Libertinus Math', monospace;
}

#answer-input-container {
  display: flex;
  align-items: center;
  gap: 0.5em;
  margin-left: 1em;
}

#answer-input {
  padding: 3px 5px;
  border: 2px solid #ccc;
  border-radius: 6px;
  font-size: 1.5rem;
  font-family: 'Libertinus Math', monospace;
  width: 190px;
  text-align: center;
  transition: border-color 0.2s;
  margin-left: 23px;
  /* iOS Safari fixes */
  -webkit-appearance: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  /* Show display value */
  position: relative;
}

#answer-input::after {
  content: attr(data-display);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  color: #333;
  font-size: 1.5rem;
  font-family: 'Libertinus Math', monospace;
}

#answer-input:focus {
  outline: none;
  border-color: #007bff;
  background-color: #f8f9fa;
}

#answer-input:disabled {
  background-color: #f5f5f5;
  color: #999;
  cursor: not-allowed;
}

#answer-prompt {
  font-size: 1.5rem;
  font-weight: bold;
  color: #222;
  font-family: 'Libertinus Math', monospace;
}

/* Unified icon button styles */
.icon-btn {
  background: #fff;
  color: #007bff;
  border: none;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2em;
  margin: 0 6px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
  cursor: pointer;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  -moz-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.icon-btn:hover, .icon-btn:focus {
  background: #007bff;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,123,255,0.12);
}

.icon-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.icon-btn:active {
  background: #f0f0f0;
}

#next-problem-btn {
  margin-left: auto;
  background: #007bff;
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3em;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  transition: background 0.2s, box-shadow 0.2s;
  cursor: pointer;
}

#next-problem-btn:hover {
  background: #0056b3;
  box-shadow: 0 4px 16px rgba(0,123,255,0.12);
}

#controls {
  display: none;
  justify-content: center;
  align-items: center;
  gap: 0.5em;
  margin: 10px 0 5px 0;
  padding: 10px;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #e9ecef;
}

#controls.visible {
  display: flex;
}

/* Practice mode specific styles */
.practice-mode #problem-area {
  display: none;
}

.practice-mode #controls {
  display: flex;
}

#practice-mode-selector,
#practice-mode-selector-label {
  display: none !important; /* Hidden by default, shown only in practice mode */
}

.practice-mode #practice-mode-selector,
.practice-mode #practice-mode-selector-label {
  display: inline-flex !important; /* Show toggle button in practice mode */
}

#practice-mode-selector-label {
  align-items: center;
  color: #344054;
  font-size: 0.95rem;
  font-weight: 600;
  margin-right: 2px;
}

#practice-mode-selector {
  min-height: 38px;
  border: 1px solid #ced4da;
  border-radius: 6px;
  background: #fff;
  color: #1f2937;
  font: inherit;
  padding: 0 34px 0 12px;
  cursor: pointer;
}

/* Floating toolbar styles */
#floating-toolbar {
  display: none;
  position: absolute;
  z-index: 2000;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  padding: 6px 10px;
  gap: 8px;
  align-items: center;
  transition: box-shadow 0.2s;
}

#floating-toolbar .icon-btn {
  background: #333;
  color: #fff;
  width: 32px;
  height: 32px;
  font-size: 1.1em;
  margin: 0 2px;
}

#floating-toolbar .icon-btn:hover {
  background: #007bff;
  color: #fff;
}

#floating-toolbar button {
  background: none;
  border: none;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.2s;
}

#floating-toolbar button:hover {
  color: #007bff;
}

#canvas-container { 
  flex: 1; 
  display: flex; 
  margin: 10px 20px;
  gap: 20px;
  align-items: stretch;
  min-height: 400px;
  /* iOS Safari fixes */
  overflow: hidden;
  touch-action: none;
  /* Ensure proper flex behavior */
  min-height: 0;
}

.equation-canvas-row {
  flex: 1;
  display: flex;
  gap: 20px;
  align-items: stretch;
  min-width: 0;
  min-height: 0;
}

.system-equation-row {
  display: none;
}

#canvas-container.system-mode {
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
  margin-bottom: 6px;
}

#canvas-container.system-mode .equation-canvas-row {
  display: flex;
}

#canvas-container.system-mode .canvas {
  min-height: 0;
}

body.dreyfous-shell-enabled #workspace #canvas-container {
  margin-right: 20px;
}

.canvas { 
  flex: 1; 
  background: #ffffff; 
  border: 1px dashed #c8cdd4; 
  position: relative; 
  overflow: hidden;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  /* iOS Safari fixes */
  touch-action: none;
}

.canvas.equation-mode {
  flex: 1;
}

.canvas.area-model-mode {
  background: #ffffff;
  border-color: #c8cdd4;
}

.area-model-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.area-model-axis-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

.area-model-overlay.area-axis-menu-open {
  z-index: 250;
}

.area-model-line {
  position: absolute;
  pointer-events: none;
}

.area-model-line-solid.area-model-line-horizontal,
.area-model-line-solid.area-model-line-vertical {
  border-color: #111;
}

.area-model-line-dash.area-model-line-horizontal,
.area-model-line-dash.area-model-line-vertical {
  border-color: #c8ced8;
}

.area-model-line-horizontal {
  border-top: 1px dashed;
}

.area-model-line-vertical {
  border-left: 1px dashed;
}

.area-model-line-solid.area-model-line-horizontal {
  border-top-style: solid;
  border-top-width: 3px;
}

.area-model-line-solid.area-model-line-vertical {
  border-left-style: solid;
  border-left-width: 3px;
}

.factorization-source-panel {
  position: absolute;
  box-sizing: border-box;
  pointer-events: none;
}

.factorization-source-panel {
  z-index: 0;
  background: #eef1f5;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

#factorization-summary-row {
  display: none;
  grid-template-columns: 36% 64%;
  align-items: center;
  width: calc(100% - 40px);
  box-sizing: border-box;
  margin: 0 20px 10px 20px;
  pointer-events: none;
}

.factorization-summary-pill {
  justify-self: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-width: 160px;
  min-height: 48px;
  padding: 6px 24px;
  border: 2px solid #20a8ff;
  border-radius: 10px;
  background: #fff;
  color: #111;
  font: 700 1.5em/1.15 'Libertinus Math', monospace;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  box-shadow: 0 4px 12px rgba(32, 168, 255, 0.18), 0 2px 6px rgba(0,0,0,0.1);
}

#factorization-source-summary {
  max-width: min(360px, calc(100% - 32px));
}

#factorization-rectangle-summary {
  max-width: min(460px, calc(100% - 32px));
}

body.dreyfous-shell-enabled #factorization-summary-row {
  position: fixed;
  left: 20px;
  right: 20px;
  bottom: 168px;
  z-index: 1250;
  width: auto;
  margin: 0;
  box-sizing: border-box;
}

@media (max-width: 1100px) {
  body.dreyfous-shell-enabled #factorization-summary-row {
    bottom: 166px;
  }
}

.area-axis-segment,
.area-axis-add {
  position: absolute;
  box-sizing: border-box;
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: #1f2633;
  font: 700 22px/1 "Times New Roman", serif;
  text-align: center;
  pointer-events: auto;
  cursor: pointer;
  touch-action: manipulation;
}

.area-axis-segment {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
}

.area-axis-segment:hover,
.area-axis-segment:focus-visible,
.area-axis-segment-active {
  background: rgba(0, 123, 255, 0.08);
  border-color: rgba(0, 123, 255, 0.22);
  color: #2a3a7a;
  box-shadow: 0 2px 8px rgba(42, 58, 122, 0.08);
  outline: none;
}

.area-axis-readonly {
  pointer-events: none;
  cursor: default;
}

.area-axis-readonly:hover {
  background: transparent;
  border-color: transparent;
  color: #1f2633;
  box-shadow: none;
}

.area-axis-left {
  min-height: 42px;
}

.area-axis-value {
  pointer-events: none;
}

.area-axis-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 999px;
  color: #007bff;
  background: transparent;
  font: 700 24px/1 Arial, sans-serif;
}

.area-axis-add:hover,
.area-axis-add:focus-visible {
  background: rgba(0, 123, 255, 0.11);
  color: #0056b3;
  outline: none;
}

.area-axis-add:disabled,
.area-axis-menu-option:disabled,
.area-axis-disabled {
  opacity: 0.38;
  cursor: not-allowed;
  box-shadow: none;
}

.area-axis-add:disabled:hover,
.area-axis-menu-option:disabled:hover {
  background: transparent;
  border-color: transparent;
  color: inherit;
}

.area-axis-menu {
  position: absolute;
  z-index: 5;
  min-width: 168px;
  box-sizing: border-box;
  border: 1px solid #d0d0e0;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 6px 22px rgba(30, 34, 60, 0.18);
  padding: 10px;
  pointer-events: auto;
}

.area-axis-menu-row {
  display: flex;
  gap: 6px;
}

.area-axis-menu-sign-row {
  margin-top: 8px;
}

.area-axis-menu-option,
.area-axis-menu-sign,
.area-axis-menu-delete {
  border: 1px solid #d0d0e0;
  border-radius: 6px;
  background: #fff;
  color: #2a3a7a;
  cursor: pointer;
  font: 700 16px/1 Arial, sans-serif;
  min-height: 32px;
}

.area-axis-menu-option,
.area-axis-menu-sign {
  flex: 1;
  min-width: 32px;
  padding: 6px 8px;
}

.area-axis-menu-option {
  font-family: "Times New Roman", serif;
  font-size: 20px;
}

.area-axis-menu-option:hover,
.area-axis-menu-sign:hover {
  border-color: #007bff;
  background: #eef6ff;
}

.area-axis-menu-option-active {
  border-color: #2a3a7a;
  background: #2a3a7a;
  color: #fff;
}

.area-axis-menu-delete {
  width: 100%;
  margin-top: 10px;
  padding: 8px 10px;
  color: #d71920;
  font-size: 13px;
}

.area-axis-menu-delete:hover {
  border-color: #d71920;
  background: #fff2f2;
}

.area-axis-derived {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #d71920;
  font: 700 24px/1.2 "Times New Roman", serif;
  pointer-events: none;
}

.area-axis-derived-left {
  writing-mode: horizontal-tb;
  transform: none;
}

.area-model-size-notice {
  position: absolute;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  z-index: 6;
  max-width: min(520px, calc(100% - 40px));
  box-sizing: border-box;
  border: 1px solid #e53935;
  border-radius: 8px;
  background: #fff2f2;
  color: #b3261e;
  padding: 10px 16px;
  font: 700 15px/1.2 Arial, sans-serif;
  text-align: center;
  box-shadow: 0 4px 16px rgba(179, 38, 30, 0.16);
  pointer-events: none;
}

.canvas-label {
  position: absolute;
  top: 10px;
  left: 10px;
  font-size: 14px;
  color: #666;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.8);
  padding: 2px 6px;
  border-radius: 3px;
}

.equation-operator {
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 60px;
  color: #666;
  font-weight: bold;
  padding: 0 10px;
  border-radius: 5px;
  margin: 0 10px;
}

.equation-operator.visible {
  display: flex;
}

.equation-operator.comparison-operator-tile {
  padding: 0;
  margin: 0 10px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.comparison-operator-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  border: 0;
  border-radius: 6px;
  background: transparent;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.comparison-operator-trigger:focus-visible {
  outline: 3px solid rgba(25, 118, 243, 0.42);
  outline-offset: 3px;
}

.equation-operator.comparison-operator-tile .comparison-operator-img {
  max-width: 80px;
  max-height: 80px;
  width: auto;
  height: auto;
  display: block;
  transition: transform 0.2s ease;
  pointer-events: auto;
}

.equation-operator.comparison-operator-tile .comparison-operator-img:active {
  transform: scale(0.95);
}

.comparison-operator-picker {
  position: fixed;
  z-index: 5450;
  display: none;
  grid-template-columns: repeat(2, 56px);
  gap: 8px;
  box-sizing: border-box;
  width: 132px;
  padding: 8px;
  border: 1px solid #dbe3ee;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.18);
}

.comparison-operator-picker.is-open {
  display: grid;
}

.comparison-operator-option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  min-width: 48px;
  height: 56px;
  min-height: 48px;
  box-sizing: border-box;
  border: 2px solid transparent;
  border-radius: 9px;
  background: #f7f9fc;
  padding: 4px;
  cursor: pointer;
  touch-action: manipulation;
}

.comparison-operator-option:hover,
.comparison-operator-option:focus-visible {
  border-color: #8cb8f7;
  background: #eef6ff;
  outline: none;
}

.comparison-operator-option.is-selected {
  border-color: #1976f3;
  background: #e8f1ff;
  box-shadow: inset 0 0 0 1px rgba(25, 118, 243, 0.18);
}

.comparison-operator-option img {
  display: block;
  width: 48px;
  height: 48px;
  object-fit: contain;
  pointer-events: none;
}

#selection-box {
  position: fixed;
  border: 2px dashed #E839E8;
  background: rgba(232, 57, 232, 0.08);
  pointer-events: none;
  z-index: 2000;
}

#toolbar { 
  display: flex; 
  justify-content: center; 
  background: #333; 
  padding: 10px; 
  gap: 10px; 
  flex-wrap: wrap; 
  align-items: center; 
  /* iOS Safari fixes */
  touch-action: manipulation;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.toolbar-actions {
  position: relative;
}

.toolbar-actions-popover {
  position: fixed;
  z-index: 5400;
  display: none;
  min-width: 220px;
  box-sizing: border-box;
  padding: 8px;
  border: 1px solid #dbe3ee;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.16);
}

.toolbar-actions-popover.is-open {
  display: block;
}

.toolbar-action-menu-item {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-sizing: border-box;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #1f2937;
  padding: 10px 12px;
  font: 700 14px/1.2 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.toolbar-action-menu-item i {
  width: 20px;
  color: #007bff;
  text-align: center;
  font-size: 1.05em;
}

.toolbar-action-menu-item:hover,
.toolbar-action-menu-item:focus-visible {
  background: #eef6ff;
  outline: none;
}

.tile-img {
  display: block;
  height: auto;
  transition: transform 0.3s cubic-bezier(0.4, 0.2, 0.2, 1);
  transform-style: preserve-3d;
  /* iOS Safari fixes */
  touch-action: manipulation;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -ms-user-select: none;
  -moz-user-select: none;
}

.tile-inner-wrapper.flipping {
  animation: tile-flip 0.4s cubic-bezier(0.4, 0.2, 0.2, 1);
}

@keyframes tile-flip {
  0% {
    transform: scaleX(1);
  }
  50% {
    transform: scaleX(0);
  }
  100% {
    transform: scaleX(1);
  }
}

/* PWA-specific styles */
@media (display-mode: standalone) {
  body {
    /* Remove browser UI when running as PWA */
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    /* Ensure proper viewport handling for iOS */
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    overflow: hidden;
  }
  
  #top-header {
    /* Add safe area padding for notched devices */
    padding-top: env(safe-area-inset-top);
  }
  
  #workspace {
    /* Ensure workspace fits properly in PWA mode */
    height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
  
  #toolbar {
    /* Ensure toolbar is fully visible with safe area padding */
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    margin-bottom: 0;
  }
  
  /* Ensure canvas container doesn't overflow */
  #canvas-container {
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }
}

/* Force tile sizes for debugging - decreased by 20% from previous size */
.tile-img[data-type="unit"] { 
  height: 69px !important; 
  width: 69px !important; 
  max-height: 69px !important; 
  max-width: 69px !important; 
}

.tile-img[data-type="x"] { 
  height: 69px !important; 
  width: 126px !important; 
  max-height: 69px !important; 
  max-width: 126px !important; 
}

.tile-img[data-type="x2"] { 
  height: 126px !important; 
  width: 126px !important; 
  max-height: 126px !important; 
  max-width: 126px !important; 
}

.tile-img[data-type="y"] { 
  height: 69px !important; 
  width: 163px !important; 
  max-height: 69px !important; 
  max-width: 163px !important; 
}

.tile-img[data-type="z"] { 
  height: 69px !important; 
  width: 188px !important; 
  max-height: 69px !important; 
  max-width: 188px !important; 
}

.tile-img[data-type="y2"] { 
  height: 163px !important; 
  width: 163px !important; 
  max-height: 163px !important; 
  max-width: 163px !important; 
}

.tile-img[data-type="xy"] { 
  height: 126px !important; 
  width: 163px !important; 
  max-height: 126px !important; 
  max-width: 163px !important; 
}

/* Also apply to canvas blocks - simplified selector */
img[data-type="unit"] { 
  height: 69px !important; 
  width: 69px !important; 
  max-height: 69px !important; 
  max-width: 69px !important; 
}

img[data-type="x"] { 
  height: 69px !important; 
  width: 126px !important; 
  max-height: 69px !important; 
  max-width: 126px !important; 
}

img[data-type="x2"] { 
  height: 126px !important; 
  width: 126px !important; 
  max-height: 126px !important; 
  max-width: 126px !important; 
}

img[data-type="y"] { 
  height: 69px !important; 
  width: 163px !important; 
  max-height: 69px !important; 
  max-width: 163px !important; 
}

img[data-type="z"] { 
  height: 69px !important; 
  width: 188px !important; 
  max-height: 69px !important; 
  max-width: 188px !important; 
}

img[data-type="y2"] { 
  height: 163px !important; 
  width: 163px !important; 
  max-height: 163px !important; 
  max-width: 163px !important; 
}

img[data-type="xy"] { 
  height: 126px !important; 
  width: 163px !important; 
  max-height: 126px !important; 
  max-width: 163px !important; 
}

.tile-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* iOS Safari fixes */
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -ms-user-select: none;
  -moz-user-select: none;
}

.tile-label {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  transform: translate(-50%, -50%);
  color: #fff;
  font-family: 'Libertinus Math', 'Times New Roman', serif;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  -webkit-text-stroke: 0.55px #111827;
  paint-order: stroke fill;
  text-shadow:
    -0.6px -0.6px 0 #111827,
    0.6px -0.6px 0 #111827,
    -0.6px 0.6px 0 #111827,
    0.6px 0.6px 0 #111827,
    1.5px 2px 2px rgba(17, 24, 39, 0.55);
  pointer-events: none;
  user-select: none;
}

.toolbar-tile-label {
  font-size: 18px;
}

.canvas-tile-label {
  font-size: 28px;
  -webkit-text-stroke-width: 0.75px;
}

#workspace.tile-labels-hidden .canvas-tile-label {
  display: none;
}

.canvas-block { 
  position: absolute; 
  z-index: 2;
  pointer-events: none;
  touch-action: none; 
  /* iOS Safari fixes */
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -ms-user-select: none;
  -moz-user-select: none;
}

.canvas-block img { 
  display: block; 
  max-width: 100%; 
  height: auto;
  pointer-events: auto;
  /* box-shadow: 0 0 5px rgba(0, 0, 0, .5); */
}

/* Ensure canvas blocks maintain proper aspect ratios */
.canvas-block[data-type="unit"] img {
  aspect-ratio: 1 / 1;
}

.canvas-block[data-type="x"] img {
  aspect-ratio: 1.84 / 1;
  height: 69px !important;
  width: 126px !important;
}

.canvas-block[data-type="x2"] img {
  aspect-ratio: 1 / 1;
}

.canvas-block[data-type="y"] img {
  aspect-ratio: 2.37 / 1;
  height: 69px !important;
  width: 163px !important;
}

.canvas-block[data-type="z"] img {
  aspect-ratio: 2.72 / 1;
  height: 69px !important;
  width: 188px !important;
}

.canvas-block[data-type="y2"] img {
  aspect-ratio: 1 / 1;
}

.canvas-block[data-type="xy"] img {
  aspect-ratio: 1.29 / 1;
}

.canvas-block.selected img {
  outline: 2px solid #E839E8;
  outline-offset: -3px;
  border-radius: 0;
  z-index: 10;
}

/* Remove the border from .canvas-block.selected itself */
.canvas-block.selected {
  box-shadow: none;
  border-radius: 0;
}

.tile-inner-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
}

/* Remove .controls-overlay styles since tile controls are gone */

.drag-preview { 
  position: fixed; 
  pointer-events: none; 
  opacity: 0.8; 
  z-index: 10000; 
  max-height: 204px; /* Updated to match largest tile (increased by 40% total) */
}

/* Shadow effect for tiles being dragged */
.canvas-block.dragging {
  transform: translateZ(0);
  transition: box-shadow 0.1s ease-out;
}

.canvas-block.dragging img {
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  transition: box-shadow 0.1s ease-out;
}

.feedback {
  margin-top: 0.5em;
  padding: 0.5em;
  border-radius: 6px;
  font-weight: 500;
  text-align: center;
  min-height: 1.2em;
}

.feedback.success {
  background-color: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.feedback.error {
  background-color: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.feedback.info {
  background-color: #d1ecf1;
  color: #0c5460;
  border: 1px solid #bee5eb;
}

/* Feedback Modal Styles */
.modal {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100vw;
  height: 100vh;
  overflow: auto;
  background-color: rgba(0,0,0,0.3);
  transition: opacity 0.2s;
}

.modal-content {
  background-color: #fff;
  margin: 10vh auto;
  padding: 2em 2.5em 1.5em 2.5em;
  border: 1px solid #888;
  border-radius: 12px;
  width: 90%;
  max-width: 420px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  position: relative;
  text-align: center;
}

.modal-close {
  color: #aaa;
  position: absolute;
  top: 12px;
  right: 18px;
  font-size: 2em;
  font-weight: bold;
  cursor: pointer;
  transition: color 0.2s;
}

.modal-close:hover {
  color: #007bff;
}

#modal-message {
  font-size: 1.15em;
  margin-top: 0.5em;
  margin-bottom: 0.5em;
  word-break: break-word;
}

#modal-message.success {
  color: #155724;
  background: #d4edda;
  border: 1px solid #c3e6cb;
  border-radius: 6px;
  padding: 0.7em 0.5em;
}

#modal-message.error {
  color: #721c24;
  background: #f8d7da;
  border: 1px solid #f5c6cb;
  border-radius: 6px;
  padding: 0.7em 0.5em;
}

#representation-feedback.feedback:empty,
#answer-feedback.feedback:empty {
  display: none;
}

#representation-feedback.feedback:not(:empty),
#answer-feedback.feedback:not(:empty) {
  display: block;
}

/* Make toolbar and buttons larger on mobile */
@media (max-width: 600px) {
  #floating-toolbar {
    padding: 12px 18px;
    gap: 16px;
  }
  
  .icon-btn {
    font-size: 2em;
    padding: 16px;
    margin: 0 6px;
  }
  
  #floating-toolbar i {
    font-size: 2em;
  }
}

.equation-row .icon-btn {
  margin-left: 0.5em;
  margin-right: 0.5em;
  background: #fff;
  color: #007bff;
  border: none;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2em;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
  cursor: pointer;
  position: relative;
}

.equation-row .icon-btn:hover, .equation-row .icon-btn:focus {
  background: #007bff;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,123,255,0.12);
}

#equation.correct {
  background: #d4edda !important;
  border-radius: 8px;
  transition: background 0.3s;  
}

#problem-list-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 270px;
  height: 100vh;
  background: linear-gradient(180deg, #f8fafc 0%, #e3e9f6 100%);
  box-shadow: 2px 0 16px rgba(60,80,120,0.10);
  z-index: 3001;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #c7d0e0;
  transition: transform 0.2s;
}

#problem-list-sidebar .sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1em 1.2em 0.7em 1.2em;
  font-weight: bold;
  font-size: 1.15em;
  border-bottom: 1px solid #e3e9f6;
  background: #e3e9f6;
  letter-spacing: 0.5px;
}

#problem-list-sidebar .icon-btn {
  background: none;
  color: #2a3550;
  font-size: 1.2em;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}

#problem-list-sidebar .icon-btn:hover {
  background: #e3e9f6;
}

#problem-list-sidebar ul {
  flex: 1;
  overflow-y: auto;
  margin: 0;
  padding: 0.5em 0 1em 0;
}

#problem-list-sidebar li {
  padding: 0.7em 1.2em 0.7em 1.5em;
  cursor: pointer;
  border-bottom: 1px solid #e3e9f6;
  font-size: 1.04em;
  color: #2a3550;
  transition: background 0.15s, color 0.15s, border-left 0.15s;
  border-left: 4px solid transparent;
  position: relative;
  background: transparent;
  user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  -moz-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#problem-list-sidebar li:hover {
  background: #e3e9f6;
  color: #007bff;
  border-left: 4px solid #b3d1ff;
}

#problem-list-sidebar li.selected {
  background: #e3e9f6;
  color: #007bff;
  border-left: 4px solid #007bff;
  font-weight: bold;
  box-shadow: 0 2px 8px rgba(0,123,255,0.06);
}

@media (max-width: 600px) {
  #problem-list-sidebar {
    width: 90vw;
    min-width: 0;
    max-width: 98vw;
  }
  
  #problem-list-sidebar .sidebar-header {
    padding: 0.7em 0.7em 0.4em 0.7em;
    font-size: 1em;
  }
  
  #problem-list-sidebar li {
    padding: 0.6em 0.7em 0.6em 1em;
    font-size: 0.98em;
  }
}

#canvas-tile-summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-width: 190px;
  max-width: min(720px, calc(100vw - 48px));
  min-height: 48px;
  box-sizing: border-box;
  background: #fff;
  color: #111;
  padding: 6px 30px;
  border: 2px solid #20a8ff;
  border-radius: 10px;
  font-size: 1.5em;
  line-height: 1.15;
  text-align: center;
  font-family: 'Libertinus Math', monospace;
  white-space: normal;
  overflow-wrap: anywhere;
  box-shadow: 0 4px 12px rgba(32, 168, 255, 0.18), 0 2px 6px rgba(0,0,0,0.1);
}

#canvas-tile-summary .summary-operator {
  display: inline-block;
  margin: 0 0.18em;
  font-family: monospace;
}

#system-equation-summaries {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  gap: 2px;
  min-height: 72px;
  margin: 0 20px 4px;
  color: #111;
  font: 700 1.35em/1.2 'Libertinus Math', monospace;
  text-align: center;
}

.system-equation-summary {
  min-height: 1.2em;
  overflow-wrap: anywhere;
}

body.dreyfous-shell-enabled #workspace.system-equations-mode {
  padding-bottom: 184px;
}

@media (max-width: 760px) {
  body.dreyfous-shell-enabled #workspace.system-equations-mode {
    padding-bottom: 184px;
  }
}

#canvas-tile-summary.area-summary-success {
  background: #f2faf2;
  color: #256d2f;
  border-color: #4caf50;
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.22), 0 2px 6px rgba(0,0,0,0.08);
}

#canvas-tile-summary.area-summary-error {
  background: #fff2f2;
  color: #b3261e;
  border-color: #e53935;
  box-shadow: 0 4px 12px rgba(229, 57, 53, 0.2), 0 2px 6px rgba(0,0,0,0.08);
}

.area-model-modal-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 22px;
}

.area-model-modal-action {
  min-width: 112px;
  border: 1px solid #2a3a7a;
  border-radius: 6px;
  padding: 10px 16px;
  font: 700 0.92em/1 Arial, sans-serif;
  cursor: pointer;
}

.area-model-modal-action-primary {
  background: #2a3a7a;
  color: #fff;
}

.area-model-modal-action-secondary {
  background: #fff;
  color: #2a3a7a;
}

#feedback-modal {
  position: fixed;
  top: 500px;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: unset;
  min-height: unset;
  background: rgba(30, 34, 60, 0.18); /* subtle overlay */
  pointer-events: none;
}

#feedback-modal .modal-content,
#feedback-modal .modal-close {
  pointer-events: auto;
}

#feedback-modal .modal-content {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 6px 32px #0002;
  padding: 32px 36px 24px 36px;
  min-width: 260px;
  max-width: 740px;
  width: 100%;
  text-align: center;
  position: relative;
  font-size: 1.18em;
  color: #2a3a7a;
  margin-top: 290px;
}

#feedback-modal .modal-close {
  position: absolute;
  top: 12px;
  right: 18px;
  font-size: 1.5em;
  color: #888;
  cursor: pointer;
  background: none;
  border: none;
}

#modal-message {
  margin-top: 12px;
  margin-bottom: 8px;
  font-size: 1.1em;
  font-weight: 500;
}

#equation.exercise-success {
  border: 1px solid #4caf50 !important;
  background: #f2faf2 !important;
  box-shadow: 0 0 8px rgba(49, 243, 0, 0.856) !important;
}

#equation.exercise-error {
  border: 3px solid #e53935 !important;
  background: #f7ecee !important;
  box-shadow: 0 0 8px rgba(254, 9, 9, 0.926) !important;
}
