*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Nunito', sans-serif;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.main-row {
  flex: 1;
  display: flex;
  flex-direction: row;
  overflow: hidden;
  min-height: 0;
}

/* ─── Canvas Area ─────────────────────────────────────────────────── */
canvas-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: linear-gradient(160deg, #b8e4f7 0%, #cdeef9 50%, #d9f2fb 100%);
  min-height: 0;
}

canvas-area .canvas-inner {
  position: absolute;
  inset: 0;
  touch-action: none;
}

canvas-area .word-group-outline {
  position: absolute;
  pointer-events: none;
  border: 2.5px solid rgba(59,130,246,0.3);
  background-color: rgba(59,130,246,0.04);
  border-radius: 17px;
}

canvas-area .snap-indicator,
canvas-area .drop-indicator {
  display: none;
  position: absolute;
  width: 31px;
  background-color: rgba(239,100,100,0.38);
  border-radius: 4px;
  pointer-events: none;
  z-index: 100;
}

/* ─── Canvas Tile ─────────────────────────────────────────────────── */
canvas-tile {
  position: absolute;
  width: 117px;
  height: 117px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 13px;
  background-color: #ffffff;
  border: 2px solid #c0c0c0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  cursor: grab;
  user-select: none;
  touch-action: none;
  z-index: 10;
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  color: #1a1a1a;
  letter-spacing: -0.5px;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

canvas-tile.selected {
  border: 3px solid #3b82f6;
}

canvas-tile:hover:not(.dragging) {
  transform: translateY(-5px) scale(1.05);
  box-shadow: 0 10px 24px rgba(0,0,0,0.18);
}

canvas-tile.dragging {
  z-index: 50;
  transform: scale(1.06);
  box-shadow: 0 12px 28px rgba(0,0,0,0.2);
}

/* ─── Drawing Layer ───────────────────────────────────────────────── */
drawing-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

drawing-layer svg {
  width: 100%;
  height: 100%;
}

/* ─── Tile Palette ────────────────────────────────────────────────── */
tile-palette {
  display: block;
  flex-shrink: 0;
  background-color: #fdeea0;
  border-top: 2px solid #d4a800;
}

tile-palette .tab-row {
  display: flex;
  flex-wrap: wrap;
  background-color: #f5c518;
  border-bottom: 1px solid #d4a800;
}

tile-palette .tab-btn {
  padding: 10px 21px;
  font-size: 20px;
  font-weight: 800;
  font-family: 'Nunito', sans-serif;
  background-color: #f5c518;
  color: #8a6200;
  border: none;
  border-right: 1px solid #d4a800;
  border-bottom: 1px solid #d4a800;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.1s;
}

tile-palette .tab-btn.active {
  background-color: #fdeea0;
  color: #5a3d00;
  border-bottom-color: #fdeea0;
  margin-bottom: -1px;
}

tile-palette .tile-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 16px;
  max-height: 260px;
  overflow-y: auto;
}

tile-palette .palette-tile {
  width: 81px;
  height: 81px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background-color: #ffffff;
  border: 2px solid #c0c0c0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  cursor: grab;
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  color: #1a1a1a;
  user-select: none;
  flex-shrink: 0;
  transition: transform 0.12s ease;
}

tile-palette .palette-tile:hover {
  transform: scale(1.05) translateY(-2px);
}

tile-palette .palette-tile:active {
  transform: scale(0.95);
}

/* ─── Toolbar ─────────────────────────────────────────────────────── */
app-toolbar {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  height: 81px;
  padding: 0 16px;
  gap: 12px;
  background-color: #f5c518;
  border-top: 2px solid #d4a800;
  font-family: 'Nunito', sans-serif;
  overflow-x: auto;
  scrollbar-width: none;
}

app-toolbar .divider {
  width: 2px;
  height: 40px;
  background-color: #d4a800;
  margin: 0 4px;
  flex-shrink: 0;
}

app-toolbar .tool-btn {
  width: 60px;
  height: 60px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 2px solid transparent;
  background-color: transparent;
  color: #6b4c00;
  cursor: pointer;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  transition: background-color 0.1s;
}

app-toolbar .tool-btn.active {
  background-color: #d4a800;
  color: #fff;
  border-color: #b8900a;
}

app-toolbar .tool-btn.danger {
  color: #dc2626;
}

app-toolbar .tool-btn:hover:not(.active) {
  background-color: rgba(212,168,0,0.2);
}

app-toolbar .word-display {
  font-size: 20px;
  font-weight: 800;
  color: #6b4c00;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

app-toolbar .word-input {
  border-radius: 8px;
  padding: 6px 12px;
  border: 2px solid #d4a800;
  background: white;
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 22px;
  color: #1a1a1a;
  width: 200px;
  outline: none;
}

app-toolbar .word-chips {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  flex: 1;
  min-width: 80px;
  scrollbar-width: none;
}

app-toolbar .word-chip {
  flex-shrink: 0;
  padding: 6px 16px;
  border-radius: 8px;
  border: 2px solid #d4a800;
  background: #ffffff;
  color: #6b4c00;
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 21px;
  cursor: pointer;
  transition: background-color 0.1s;
}

app-toolbar .word-chip:hover {
  background-color: #fdeea0;
}

app-toolbar .tile-count {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
  color: #6b4c00;
}

app-toolbar .tile-count .label { font-size: 17px; font-weight: 800; }
app-toolbar .tile-count .count { font-size: 23px; font-weight: 900; }
app-toolbar .tile-count .sel { font-size: 14px; font-weight: 700; color: #3b82f6; }

app-toolbar .speak-btn,
app-toolbar .lookup-btn {
  width: 49px;
  height: 49px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border: 2px solid #d4a800;
  color: #6b4c00;
  cursor: pointer;
  transition: background-color 0.1s;
}

app-toolbar .speak-btn:hover,
app-toolbar .lookup-btn:hover {
  background-color: #fdeea0;
}

/* ─── Dictionary Panel ────────────────────────────────────────────── */
dictionary-panel {
  display: none;
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 360px;
  background: white;
  border-left: 1px solid #e2e8f0;
  box-shadow: -4px 0 20px rgba(0,0,0,0.1);
  z-index: 50;
  flex-direction: column;
  animation: slideInRight 0.2s ease;
}

dictionary-panel.open {
  display: flex;
}

@keyframes slideInRight {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

dictionary-panel .panel-header {
  height: 56px;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: #f8fafc;
  flex-shrink: 0;
}

dictionary-panel .panel-header h2 {
  font-weight: 700;
  color: #1e293b;
  font-size: 16px;
}

dictionary-panel .panel-close {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  cursor: pointer;
  color: #64748b;
  font-size: 20px;
  border-radius: 6px;
}

dictionary-panel .panel-close:hover {
  background: #f1f5f9;
}

dictionary-panel .panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

dictionary-panel .word-title {
  font-size: 36px;
  font-weight: 900;
  color: #0f172a;
  margin-bottom: 8px;
}

dictionary-panel .phonetic {
  font-family: monospace;
  font-size: 18px;
  color: #475569;
  background: #f1f5f9;
  padding: 2px 8px;
  border-radius: 4px;
}

dictionary-panel .listen-btn {
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid #bfdbfe;
  background: white;
  color: #2563eb;
  font-size: 14px;
  cursor: pointer;
}

dictionary-panel .listen-btn:hover {
  background: #eff6ff;
}

dictionary-panel .pos-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #2563eb;
  background: #eff6ff;
  padding: 4px 8px;
  border-radius: 4px;
}

dictionary-panel .definition {
  color: #334155;
  line-height: 1.6;
  margin-top: 8px;
}

dictionary-panel .example {
  color: #64748b;
  font-style: italic;
  font-size: 14px;
  border-left: 2px solid #cbd5e1;
  padding-left: 12px;
  margin-top: 6px;
}

dictionary-panel .error-msg {
  color: #dc2626;
  text-align: center;
  margin-top: 40px;
  background: #fef2f2;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid #fecaca;
}

dictionary-panel .empty-msg {
  color: #64748b;
  text-align: center;
  margin-top: 40px;
}

/* ─── Word Bank Panel ─────────────────────────────────────────────── */
word-bank-panel {
  display: none;
  flex-shrink: 0;
  flex-direction: column;
  width: min(270px, 100vw);
  background-color: #fff9e6;
  border-left: 2px solid #d4a800;
  overflow: hidden;
  font-family: 'Nunito', sans-serif;
}

word-bank-panel.open {
  display: flex;
}

word-bank-panel .wb-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 2px solid #d4a800;
  background-color: #f5c518;
  font-size: 22px;
  font-weight: 900;
  color: #5a3d00;
}

word-bank-panel .wb-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 12px 8px;
  flex-shrink: 0;
}

word-bank-panel .wb-input {
  flex: 1;
  min-width: 0;
  border-radius: 8px;
  padding: 8px 12px;
  border: 2px solid #d4a800;
  background: white;
  font-size: 19px;
  font-weight: 700;
  font-family: 'Nunito', sans-serif;
  color: #1a1a1a;
  outline: none;
}

word-bank-panel .wb-add-btn {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5c518;
  border: 2px solid #d4a800;
  color: #5a3d00;
  cursor: pointer;
  font-size: 24px;
  font-weight: 900;
  flex-shrink: 0;
}

word-bank-panel .wb-add-btn:hover {
  background: #d4a800;
  color: white;
}

word-bank-panel .wb-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

word-bank-panel .wb-empty {
  font-size: 15px;
  color: #9a7a00;
  font-weight: 600;
  text-align: center;
  margin-top: 20px;
  line-height: 1.5;
}

word-bank-panel .wb-word {
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 12px;
  border: 2px solid #d4a800;
  background: white;
  padding: 8px 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}

word-bank-panel .wb-word-label {
  flex: 1;
  font-size: 23px;
  font-weight: 800;
  color: #1a1a1a;
  cursor: pointer;
  background: none;
  border: none;
  text-align: left;
  font-family: 'Nunito', sans-serif;
}

word-bank-panel .wb-word-label:hover {
  color: #b8900a;
}

word-bank-panel .wb-place-btn {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5c518;
  border: 1px solid #d4a800;
  color: #5a3d00;
  cursor: pointer;
  flex-shrink: 0;
}

word-bank-panel .wb-place-btn:hover {
  background: #d4a800;
  color: white;
}

word-bank-panel .wb-remove-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: #f87171;
  cursor: pointer;
  flex-shrink: 0;
}

word-bank-panel .wb-remove-btn:hover {
  background: #fee2e2;
  color: #dc2626;
}

/* ─── Confirm Dialog ──────────────────────────────────────────────── */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.confirm-dialog {
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  max-width: 400px;
  width: 90%;
}

.confirm-dialog h3 {
  font-size: 18px;
  font-weight: 700;
  color: #111;
  margin-bottom: 8px;
}

.confirm-dialog p {
  color: #555;
  font-size: 14px;
  margin-bottom: 20px;
}

.confirm-dialog .btn-row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.confirm-dialog button {
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
}

.confirm-dialog .btn-cancel {
  background: white;
  border: 1px solid #d1d5db;
  color: #374151;
}

.confirm-dialog .btn-confirm {
  background: #dc2626;
  border: none;
  color: white;
}

.confirm-dialog .btn-confirm:hover {
  background: #b91c1c;
}
