* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Segoe UI', Arial, sans-serif; background: #1a1a2e; color: #333; overflow: hidden; height: 100vh; }
input, select, button { font-family: inherit; }

/* ===== LOGIN ===== */
.login-body { display: flex; align-items: center; justify-content: center; }
.login-container { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-box {
  background: #fff; border-radius: 20px; padding: 40px; width: 100%; max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3); text-align: center;
}
.logo { margin-bottom: 10px; }
.login-box h1 { font-family: Impact, sans-serif; font-size: 36px; color: #1a1a2e; letter-spacing: 2px; margin-bottom: 4px; }
.subtitle { color: #888; font-size: 14px; margin-bottom: 30px; }
.form-group { margin-bottom: 18px; text-align: left; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: #555; margin-bottom: 6px; }
.form-group input {
  width: 100%; padding: 12px 16px; border: 2px solid #e0e0e0; border-radius: 10px;
  font-size: 15px; transition: border-color 0.2s; outline: none;
}
.form-group input:focus { border-color: #6c63ff; }
.btn-login {
  width: 100%; padding: 14px; background: #6c63ff; color: #fff; border: none; border-radius: 10px;
  font-size: 16px; font-weight: 700; cursor: pointer; transition: background 0.2s; margin-top: 10px;
}
.btn-login:hover { background: #5a52e0; }
.btn-login:disabled { background: #999; cursor: not-allowed; }
.error-msg { background: #ffe0e0; color: #c00; padding: 10px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.register-note { margin-top: 20px; font-size: 12px; color: #aaa; }

/* ===== EDITOR ===== */
#app { display: flex; flex-direction: column; height: 100vh; }

#topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: #16213e; padding: 6px 12px; border-bottom: 3px solid #ffd700; flex-shrink: 0; gap: 8px;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-left .brand { font-family: Impact, sans-serif; font-size: 20px; color: #ffd700; letter-spacing: 1px; white-space: nowrap; }
.topbar-left input { background: #0f3460; border: 1px solid #1a1a4e; color: #fff; padding: 6px 10px; border-radius: 6px; font-size: 13px; width: 200px; max-width: 30vw; }
.topbar-left input::placeholder { color: #668; }
.topbar-right { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.btn {
  padding: 6px 12px; border: none; border-radius: 6px; cursor: pointer; font-size: 12px;
  font-weight: 600; background: #e94560; color: #fff; transition: all 0.2s; white-space: nowrap;
}
.btn:hover { filter: brightness(1.1); }
.btn-danger { background: #c0392b; }
.btn-icon { background: transparent; color: #8899bb; padding: 6px 8px; font-size: 16px; }
.btn-icon:hover { color: #ffd700; }

/* ===== SCRIM / TOGGLE ===== */
#scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 99; }

#editor { display: flex; flex: 1; overflow: hidden; position: relative; }

/* ===== TOOLBAR ===== */
#toolbar {
  width: 90px; background: #16213e; padding: 10px 6px; display: flex; flex-direction: column;
  gap: 3px; overflow-y: auto; flex-shrink: 0; border-right: 1px solid #1a1a4e;
  transition: transform 0.25s ease;
}
.tool-group-label { font-size: 9px; color: #667; text-transform: uppercase; letter-spacing: 1px; padding: 6px 2px 2px; font-weight: 700; }
.tool-btn {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  background: transparent; border: 1px solid transparent; color: #8899bb; padding: 5px 3px;
  border-radius: 6px; cursor: pointer; transition: all 0.15s; font-size: 9px;
}
.tool-btn:hover { background: #0f3460; color: #ffd700; }
.tool-btn span { line-height: 1.2; }
.tool-separator { height: 1px; background: #1a1a4e; margin: 4px 0; }

/* ===== CANVAS ===== */
#canvas-area {
  flex: 1; display: flex; align-items: center; justify-content: center;
  background: #1a1a2e; overflow: hidden; padding: 10px; position: relative;
}
#canvas-viewport {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%; overflow: hidden; position: relative;
}
#canvas-stage {
  display: flex; align-items: center; justify-content: center;
  transform-origin: center center;
}
.comic-page-inner {
  position: relative; width: 800px; height: 1100px; background: #fff;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4); overflow: hidden;
  border-radius: 3px;
}
#elements-container { position: absolute; inset: 0; pointer-events: auto; }
.comic-element {
  position: absolute; cursor: move; user-select: none;
  border: 2px solid transparent; transition: border-color 0.15s;
  overflow: visible;
}
.comic-element.selected {
  border-color: #ffd700; box-shadow: 0 0 0 2px rgba(255,215,0,0.3), 0 0 10px rgba(255,215,0,0.2);
}
.comic-element:hover { border-color: rgba(255,215,0,0.5); }
.element-inner {
  width: 100%; height: 100%; border-style: solid;
  overflow: hidden; position: relative;
  z-index: 2;
}
.comic-element svg {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  pointer-events: none;
  overflow: visible;
  z-index: 1;
}
.resize-handle {
  position: absolute; width: 12px; height: 12px; background: #ffd700;
  border: 2px solid #333; border-radius: 2px; z-index: 10;
}
.resize-nw { top: -7px; left: -7px; cursor: nw-resize; }
.resize-ne { top: -7px; right: -7px; cursor: ne-resize; }
.resize-sw { bottom: -7px; left: -7px; cursor: sw-resize; }
.resize-se { bottom: -7px; right: -7px; cursor: se-resize; }
.bubble-tail {
  position: absolute; bottom: -18px; width: 20px; height: 20px;
  transform: rotate(45deg); left: 50%; margin-left: -10px;
  border-right: 3px solid; border-bottom: 3px solid;
  border-color: inherit; z-index: -1;
}
.tail-handle {
  position: absolute; width: 18px; height: 18px; background: #ffd700;
  border: 2.5px solid #222; border-radius: 50%; z-index: 10;
  cursor: crosshair; box-shadow: 0 0 8px rgba(255,215,0,0.6);
  transition: transform 0.12s;
}
.tail-handle:hover { transform: scale(1.3); }
.element-inner::-webkit-scrollbar { width: 4px; }
.element-inner::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

#zoom-controls {
  position: absolute; top: 8px; right: 8px; display: flex; align-items: center; gap: 3px;
  background: rgba(22,33,62,0.85); padding: 4px 6px; border-radius: 8px; z-index: 20;
  border: 1px solid #1a1a4e; backdrop-filter: blur(4px);
}
.zoom-btn {
  width: 28px; height: 28px; border: none; background: transparent; color: #ccc;
  font-size: 16px; font-weight: 700; cursor: pointer; border-radius: 4px;
  display: flex; align-items: center; justify-content: center; line-height: 1;
}
.zoom-btn:hover { background: #0f3460; color: #ffd700; }
#zoom-label { color: #ffd700; font-size: 11px; min-width: 38px; text-align: center; font-weight: 600; }

#page-controls { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; white-space: nowrap; background: rgba(22,33,62,0.7); padding: 4px 12px; border-radius: 8px; }
#page-controls .btn-sm {
  padding: 5px 14px; background: #e94560; color: #fff; border: none; border-radius: 6px;
  font-size: 12px; cursor: pointer; font-weight: 600;
}
#page-indicator { color: #8899bb; font-size: 12px; }

/* ===== PROPERTIES ===== */
#properties {
  width: 270px; background: #16213e; padding: 14px; overflow-y: auto;
  flex-shrink: 0; border-left: 1px solid #1a1a4e;
  transition: transform 0.25s ease;
}
#properties h3 { color: #ffd700; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 14px; }
.hint { color: #667; font-size: 12px; font-style: italic; text-align: center; padding: 20px 0; }
.prop-group {
  display: flex; align-items: center; gap: 6px; margin-bottom: 8px;
  color: #ccc; font-size: 11px;
}
.prop-group label { width: 70px; flex-shrink: 0; font-weight: 600; color: #8899bb; font-size: 11px; }
.prop-group input[type="text"],
.prop-group input[type="number"],
.prop-group select {
  flex: 1; min-width: 0; background: #0f3460; color: #fff; border: 1px solid #1a1a4e;
  padding: 5px 7px; border-radius: 4px; font-size: 11px; outline: none;
}
.prop-group input[type="text"]:focus,
.prop-group select:focus { border-color: #ffd700; }
.prop-group input[type="color"] { width: 32px; height: 26px; padding: 1px; border: 1px solid #1a1a4e; border-radius: 4px; background: transparent; cursor: pointer; }
.prop-group input[type="range"] { flex: 1; accent-color: #ffd700; height: 20px; }
.prop-group .num-small { width: 60px; flex: none; text-align: center; }
.range-val { color: #ffd700; font-size: 10px; min-width: 30px; text-align: right; }
.prop-value { color: #ddd; font-size: 11px; }
.prop-separator { height: 1px; background: #1a1a4e; margin: 10px 0; }
.btn-xs {
  padding: 3px 8px; font-size: 10px; background: #0f3460; color: #ccc;
  border: 1px solid #1a1a4e; border-radius: 4px; cursor: pointer;
}
.btn-xs:hover { background: #1a1a4e; color: #ffd700; }

/* ===== MODAL ===== */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex;
  align-items: center; justify-content: center; z-index: 1000;
}
.modal-content {
  background: #fff; border-radius: 14px; padding: 24px; width: 90%; max-width: 500px;
  max-height: 80vh; overflow-y: auto;
}
.modal-content h2 { color: #1a1a2e; font-family: Impact, sans-serif; margin-bottom: 16px; font-size: 22px; }
.comic-list-item {
  padding: 10px 14px; border: 1px solid #e0e0e0; border-radius: 8px; margin-bottom: 6px;
  cursor: pointer; display: flex; justify-content: space-between; align-items: center;
  transition: all 0.15s; font-size: 14px;
}
.comic-list-item:hover { border-color: #6c63ff; background: #f0f0ff; }
.comic-list-item span { color: #999; font-size: 11px; }

/* ===== SCROLLBARS ===== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  #properties { width: 240px; }
  #toolbar { width: 80px; }
}

@media (max-width: 820px) {
  #properties {
    position: fixed; top: 0; right: 0; width: 280px; height: 100vh; z-index: 100;
    transform: translateX(100%); border-left: 2px solid #ffd700;
  }
  #properties.open { transform: translateX(0); }
  #scrim.show { display: block; pointer-events: auto; }
  #canvas-area { padding: 6px; }
  #toolbar { width: 72px; padding: 8px 4px; }
  .tool-btn { padding: 4px 2px; }
  .tool-btn svg { width: 22px; height: 22px; }
  .topbar-left input { width: 140px; }
}

@media (max-width: 600px) {
  #topbar { flex-wrap: wrap; padding: 4px 8px; gap: 4px; }
  .topbar-left .brand { font-size: 16px; }
  .topbar-left input { width: 100px; font-size: 12px; max-width: 40vw; }
  .topbar-right .btn { font-size: 11px; padding: 4px 8px; }

  #editor { flex-direction: column; }
  #toolbar {
    position: fixed; bottom: 0; left: 0; right: 0; width: 100%; height: auto;
    flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 2px;
    padding: 4px 6px; border-right: none; border-top: 2px solid #ffd700;
    z-index: 50; overflow-x: auto;
  }
  #toolbar .tool-group-label { display: none; }
  #toolbar .tool-separator { width: 1px; height: 30px; margin: 0 4px; flex-shrink: 0; }
  .tool-btn { padding: 3px 6px; min-width: 48px; flex-shrink: 0; }
  .tool-btn svg { width: 20px; height: 20px; }
  .tool-btn span { font-size: 8px; }

  #canvas-area { padding: 4px; padding-bottom: 76px; }
  #zoom-controls { top: 4px; right: 4px; padding: 2px 4px; }
  .zoom-btn { width: 24px; height: 24px; font-size: 14px; }
  #zoom-label { font-size: 10px; min-width: 32px; }
  #page-controls { bottom: 2px; padding: 2px 8px; font-size: 11px; }
  #properties {
    width: 260px; font-size: 11px;
  }
  .prop-group label { width: 60px; font-size: 10px; }
  .prop-group input[type="text"], .prop-group select { font-size: 10px; }
  .comic-page-inner { width: 400px; height: 550px; }
  .resize-handle { width: 10px; height: 10px; }
  .resize-nw { top: -6px; left: -6px; }
  .resize-ne { top: -6px; right: -6px; }
  .resize-sw { bottom: -6px; left: -6px; }
  .resize-se { bottom: -6px; right: -6px; }
}

@media (max-width: 400px) {
  .topbar-right .btn { font-size: 10px; padding: 3px 6px; }
  .btn-icon { font-size: 14px; padding: 4px 6px; }
  .login-box { padding: 24px 16px; }
  .login-box h1 { font-size: 28px; }
}
@media (max-height: 600px) {
  .login-box { padding: 20px 16px; }
  .login-box h1 { font-size: 24px; margin-bottom: 0; }
  .subtitle { margin-bottom: 16px; font-size: 12px; }
  .form-group { margin-bottom: 10px; }
  .form-group input { padding: 8px 12px; font-size: 14px; }
  .btn-login { padding: 10px; font-size: 14px; }
}
