* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #1a1a2e;
  color: #eee;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem;
  overscroll-behavior: none;
  touch-action: pan-y;
  overflow-x: hidden;
  overflow-y: auto;
}

h1 {
  font-size: 2rem;
  margin-bottom: 1.5rem;
  color: #e94560;
}

.input-area {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

input[type="number"] {
  font-size: 1.4rem;
  padding: 0.5rem 1rem;
  border: 2px solid #e94560;
  border-radius: 8px;
  background: #16213e;
  color: #eee;
  width: 200px;
  outline: none;
}

#divisorInput {
  width: 120px;
}

input[type="number"]:focus {
  border-color: #f6a623;
}

button {
  font-size: 1.4rem;
  padding: 0.5rem 1.5rem;
  border: none;
  border-radius: 8px;
  background: #e94560;
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
}

button:hover { background: #c81e45; }
button:disabled { background: #555; cursor: not-allowed; }

.op-toggle {
  display: flex;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid #e94560;
}

.op-toggle button {
  border-radius: 0;
  padding: 0.4rem 1.2rem;
  font-size: 1.1rem;
  background: #16213e;
  color: #aaa;
  border: none;
  transition: background 0.2s, color 0.2s;
}

.op-toggle button.active {
  background: #e94560;
  color: #fff;
}

.op-toggle button:hover:not(.active) {
  background: #1f3460;
  color: #eee;
}

.equation {
  font-size: 1.6rem;
  margin-bottom: 0.5rem;
  min-height: 2rem;
  color: #ccc;
}

.animation-area {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  position: relative;
  width: 100%;
  overflow-x: clip;
  overflow-y: visible;
}

.digit-container {
  display: flex;
  align-items: baseline;
  position: relative;
  font-size: 4rem;
  font-family: 'Consolas', 'Courier New', monospace;
  font-weight: bold;
  transform-origin: center bottom;
  transition: transform 0.3s ease;
  padding-top: 2.5rem;
}

.digit-container .digit {
  display: inline-flex;
  justify-content: center;
  align-items: baseline;
  width: 2.4ch;
  text-align: center;
  transition: opacity 0.4s ease, width 0.4s ease;
  position: relative;
}

.digit-container .dot {
  display: inline-flex;
  justify-content: center;
  align-items: baseline;
  width: 0.8ch;
  text-align: center;
  color: #f6a623;
  transition: opacity 0.4s ease, width 0.4s ease;
  position: relative;
}

.digit-container .fade-in {
  opacity: 0;
}

.digit-container .visible {
  opacity: 1;
}

.label {
  position: absolute;
  top: -1.8rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.75rem;
  color: #f6a623;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.label.visible {
  opacity: 1;
}

.cleanup-label {
  position: absolute;
  top: -2rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  color: #e94560;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

.cleanup-label.visible {
  opacity: 1;
}

.digit-container.fast-forward,
.digit-container.fast-forward * {
  transition: none !important;
}


.result-display {
  font-size: 1.8rem;
  color: #0f3460;
  background: #f6a623;
  padding: 0.75rem 2rem;
  border-radius: 12px;
  opacity: 0;
  transition: opacity 0.5s ease;
  font-weight: bold;
}

.result-display.visible {
  opacity: 1;
}

.move-indicator {
  font-size: 1rem;
  color: #f6a623;
  margin-bottom: 0.5rem;
  min-height: 1.5rem;
}

.nav-area {
  position: fixed;
  bottom: 2rem;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 2rem;
  pointer-events: none;
  z-index: 100;
}

.nav-btn {
  font-size: 2rem;
  padding: 0.6rem 1.2rem;
  background: none;
  border: none;
  color: #e94560;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  font-weight: bold;
  line-height: 1;
}

.nav-btn.active {
  opacity: 0.6;
  pointer-events: auto;
}

.nav-btn:hover {
  opacity: 1;
  background: none;
}

.nav-btn:disabled {
  background: none;
}

.result-wrapper {
  min-height: 3.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4rem;
}

.help-btn {
  position: fixed;
  top: 1rem;
  right: 1rem;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: #16213e;
  border: 2px solid #e94560;
  color: #e94560;
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  z-index: 200;
  transition: background 0.2s;
}

.help-btn:hover {
  background: #e94560;
  color: #fff;
}

.help-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 300;
  align-items: center;
  justify-content: center;
}

.help-overlay.visible {
  display: flex;
}

.help-content {
  background: #16213e;
  border: 2px solid #e94560;
  border-radius: 12px;
  padding: 1.5rem 2rem;
  max-width: 420px;
  width: 90%;
  position: relative;
  color: #ddd;
  font-size: 0.95rem;
  line-height: 1.5;
}

.help-content h2 {
  color: #e94560;
  margin-bottom: 0.5rem;
  font-size: 1.3rem;
}

.help-content h3 {
  color: #f6a623;
  margin-top: 0.8rem;
  margin-bottom: 0.3rem;
  font-size: 1rem;
}

.help-content ul {
  list-style: none;
  padding: 0;
}

.help-content li {
  padding: 0.2rem 0;
}

.help-content p {
  margin: 0.4rem 0;
}

.help-close {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  background: none;
  border: none;
  color: #aaa;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.help-close:hover {
  color: #fff;
  background: none;
}

@media (max-width: 600px) {
  body { padding: 1rem 1rem 5rem; overflow-y: hidden; }
  h1 { font-size: 1.4rem; margin-bottom: 1rem; }
  .input-area { gap: 0.5rem; }
  input[type="number"] { font-size: 1.1rem; padding: 0.4rem 0.6rem; width: 140px; }
  #divisorInput { width: 90px; }
  button { font-size: 1.1rem; padding: 0.4rem 1rem; }
  .op-toggle button { font-size: 0.95rem; padding: 0.35rem 0.8rem; }
  .digit-container { font-size: 2.8rem; padding-top: 2rem; }
  .equation { font-size: 1.2rem; }
  .result-display { font-size: 1.4rem; padding: 0.5rem 1.2rem; }
  .move-indicator { font-size: 0.9rem; }
}

@media (max-width: 380px) {
  .digit-container { font-size: 2rem; padding-top: 1.8rem; }
  .digit-container .digit { width: 2ch; }
  .digit-container .dot { width: 0.7ch; }
  input[type="number"] { width: 110px; font-size: 1rem; }
  #divisorInput { width: 70px; }
  button { font-size: 1rem; padding: 0.35rem 0.8rem; }
}
