:root {
  color-scheme: light;
  --paper: #f7f7f4;
  --ink: #151515;
  --line: #b8b8b2;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-border: rgba(28, 28, 26, 0.18);
  --accent: #175bff;
  --accent-hover: #0e49d6;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button {
  font: inherit;
}

.app {
  position: fixed;
  inset: 0;
  display: grid;
  background:
    linear-gradient(rgba(22, 22, 20, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(22, 22, 20, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 32px 32px;
}

#stage {
  width: 100vw;
  height: 100vh;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.author-link {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  z-index: 2;
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 8px 24px rgba(20, 20, 18, 0.1);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  backdrop-filter: blur(14px);
}

.author-label {
  color: rgba(21, 21, 21, 0.52);
  font-weight: 600;
}

.telegram-icon {
  width: 17px;
  height: 17px;
  fill: currentColor;
  flex: 0 0 17px;
}

.author-link:active {
  transform: translateY(1px);
}

.toolbar {
  position: fixed;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 2;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 34px rgba(20, 20, 18, 0.13);
  backdrop-filter: blur(14px);
}

.tool-button {
  min-width: 48px;
  height: 48px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.mode-switch {
  height: 48px;
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: rgba(18, 18, 16, 0.06);
}

.mode-button {
  min-width: 82px;
  height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
  background: transparent;
  color: rgba(21, 21, 21, 0.72);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.mode-button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(20, 20, 18, 0.12);
}

.tool-button:active {
  transform: translateY(1px);
}

.tool-button:disabled {
  opacity: 0.38;
  cursor: default;
}

.tool-button:disabled:active {
  transform: none;
}

.tool-button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tool-button.primary:hover {
  background: var(--accent-hover);
}

.tool-button.icon-only {
  width: 48px;
  padding: 0;
}

.percent-button {
  min-width: 60px;
  padding: 0 10px;
  font-weight: 600;
}

.icon {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  display: inline-block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.plus::before,
.plus::after,
.minus::before {
  content: "";
  position: absolute;
  background: currentColor;
}

.plus,
.minus {
  position: relative;
}

.plus::before {
  left: 9px;
  top: 3px;
  width: 2px;
  height: 14px;
}

.plus::after {
  left: 3px;
  top: 9px;
  width: 14px;
  height: 2px;
}

.minus::before {
  left: 3px;
  top: 9px;
  width: 14px;
  height: 2px;
}

@media (max-width: 520px) {
  .author-link {
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    height: 32px;
    padding: 0 10px;
    font-size: 13px;
  }

  .toolbar {
    bottom: max(10px, env(safe-area-inset-bottom));
    right: max(12px, env(safe-area-inset-right));
    left: max(12px, env(safe-area-inset-left));
    justify-content: flex-start;
    gap: 6px;
    padding: 6px;
  }

  .tool-button.primary {
    flex: 1 1 auto;
  }

  .mode-switch {
    flex: 0 0 100%;
    width: 100%;
  }

  .tool-button {
    min-width: 42px;
    height: 42px;
    padding: 0 10px;
  }

  .tool-button.icon-only {
    width: 42px;
  }

  .percent-button {
    min-width: 54px;
    font-size: 13px;
  }

  .mode-switch {
    height: 42px;
  }

  .mode-button {
    height: 34px;
    min-width: 0;
  }
}

@media (max-width: 380px) {
  .toolbar {
    gap: 5px;
  }

  .tool-button.primary span:last-child {
    display: none;
  }

  .tool-button.primary {
    flex: 0 0 42px;
    padding: 0;
  }
}
