/* ==========================================================
   1. FONTS REGISTRATION & ICON SYSTEM
   ========================================================== */
@font-face {
  font-family: 'PixbobSans';
  src: url('Pixbob_Sans.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'PixbobSans';
  src: url('Pixbob_Sans_Bold.ttf') format('truetype');
  font-weight: bold;
  font-style: normal;
}

@font-face {
  font-family: 'PixBob Icons';
  src: url('PixBob_Icons.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

.icon-font {
  font-family: 'PixBob Icons', sans-serif !important;
  font-style: normal;
  font-weight: normal;
  font-size: 18px;
  line-height: 1;
  text-transform: none !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
}

/* Ukuran khusus icon font berdasarkan konteks */
.vertical-toolbar .btn-tool .icon-font {
  font-size: 20px;
}

.header-actions .icon-font,
.canvas-actions .icon-font {
  font-size: 18px;
}

.icon-btn .icon-font {
  color: currentColor;
  font-size: 16px;
}


/* ==========================================================
   2. GLOBAL STYLES & LAYOUT BASE
   ========================================================== */
* { 
  box-sizing: border-box; 
  margin: 0; 
  padding: 0; 
}

html, body {
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}

body { 
  font-family: 'PixbobSans', 'Courier New', Courier, monospace; 
  background-color: #18181c; 
  color: #a0a0ac; 
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 20px;

  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: none;
  font-smooth: never;
  text-rendering: optimizeSpeed;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.panel { 
  background: #222228; 
  border: 2px solid #303038; 
  padding: 20px; 
  box-shadow: 0 6px 0px #08080a; 
}

.app-layout { 
  display: flex; 
  gap: 20px; 
  flex-wrap: nowrap; 
  width: 100%;
  max-width: 1100px;
  flex: 1;
  min-height: 0;
}


/* ==========================================================
   3. HEADER & POPOVER MENUS
   ========================================================== */
header { 
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  gap: 16px;
  margin-bottom: 16px; 
  border-bottom: 2px solid #303038; 
  padding-bottom: 12px; 
  width: 100%;
  max-width: 1100px;
  flex-shrink: 0;
}

.brand-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}

.app-logo {
  height: 28px;
  width: auto;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.file-status {
  font-size: 13px;
  color: #a0a0ac;
  letter-spacing: 0.5px;
}

.header-actions { 
  display: flex; 
  align-items: center; 
  gap: 8px; 
  flex-wrap: wrap;
  justify-content: flex-end;
}

.save-wrapper,
.export-wrapper {
  position: relative;
  display: inline-block;
}

.save-popover,
.export-popover {
  display: none;
  position: absolute;
  top: 110%;
  right: 0;
  background: #222228;
  border: 2px solid #303038;
  box-shadow: 0 4px 0px #08080a;
  box-sizing: border-box;
  flex-direction: column;
  z-index: 1000;
}

.save-popover {
  width: 140px;
  padding: 6px;
  gap: 6px;
}

.export-popover {
  width: 220px;
  padding: 10px;
  gap: 8px;
}

.save-popover.show,
.export-popover.show {
  display: flex;
}

.save-popover button {
  width: 100%;
  justify-content: flex-start;
  font-size: 11px;
  box-shadow: none;
}

.export-popover label {
  font-size: 10px;
  color: #a0a0ac;
  text-transform: uppercase;
  font-weight: bold;
}

.export-popover input[type="text"] {
  background: #101012; 
  border: 2px solid #303038; 
  color: #ffffff; 
  padding: 8px 10px; 
  font-family: inherit;
  font-size: 13px;
  width: 100%;
  outline: none;
}

.export-popover input[type="text"]:focus {
  border-color: #ff9e3b;
}


/* ==========================================================
   4. BUTTON STYLES & UI CONTROLS
   ========================================================== */
button { 
  padding: 8px 12px; 
  border-radius: 0px; 
  border: 2px solid #303038; 
  font-family: inherit;
  font-weight: bold; 
  font-size: 12px;
  text-transform: uppercase !important;
  cursor: pointer; 
  transition: all 0.1s ease; 
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 3px 0px #08080a;
}

button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0px #08080a;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
  transform: none !important;
}

.btn-primary { 
  background: #d47028; 
  color: #ffffff; 
  border-color: #ff9e3b; 
}
.btn-primary:hover { 
  background: #ffffff; 
  color: #d47028; 
  border-color: #ff9e3b; 
}

.btn-secondary { 
  background: #4a505b; 
  color: #f0f2f5; 
  border-color: #6c7380; 
}
.btn-secondary:hover { 
  background: #5a616e; 
  color: #ffffff; 
  border-color: #8b93a0;
}

.btn-danger { 
  background: #4a505b; 
  color: #f0f2f5; 
  border-color: #6c7380; 
}
.btn-danger:hover { 
  background: #e57e34; 
  color: #ffffff;
  border-color: #ff9e3b; 
}

.icon-btn {
  color: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#btnClear:focus,
#btnClear:focus-visible {
  outline: none;
  box-shadow: none;
}

@media (hover: hover) {
  #btnClear:hover {
    background-color: var(--danger-color, #e74c3c);
    color: #fff;
  }
}

#btnClear:active {
  background-color: var(--danger-color, #e74c3c);
  color: #fff;
}


/* ==========================================================
   5. LEFT PANEL: EDITOR SECTION & CANVAS
   ========================================================== */
.editor-section { 
  display: flex; 
  flex-direction: column; 
  gap: 16px; 
  align-items: stretch; 
  width: auto; 
  min-width: 324px;
  box-sizing: border-box;
}

.active-char-box { 
  display: flex; 
  align-items: center; 
  gap: 10px; 
  width: 100%; 
  justify-content: space-between; 
  box-sizing: border-box;
}

.active-char-box span { 
  font-size: 13px; 
  font-weight: bold; 
  text-transform: uppercase; 
  color: #ffffff; 
}

.active-char-box input { 
  background: #101012; 
  border: 2px solid #303038; 
  color: #ff9e3b; 
  font-family: inherit;
  font-size: 16px; 
  font-weight: bold; 
  width: 46px; 
  text-align: center; 
  padding: 4px; 
  outline: none;
}

.glyph-navigation {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.glyph-navigation input {
  text-align: center;
  width: 32px;
  height: 32px;
  font-size: 14px;
  padding: 0;
}

.glyph-navigation .icon-btn {
  width: 28px;
  height: 28px;
  font-size: 11px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  color: #050505;
}

.glyph-navigation .icon-btn:focus,
.glyph-navigation .icon-btn:focus-visible {
  outline: none;
  box-shadow: none;
}

.editor-workspace {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
}

.vertical-toolbar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 36px;
  flex-shrink: 0;
}

.btn-tool { 
  padding: 8px; 
  border: 2px solid #303038; 
  background: #18181c; 
  color: #a0a0ac; 
  justify-content: center; 
  box-shadow: 0 3px 0px #08080a;
}

.btn-tool:hover { 
  color: #ffffff; 
  background: #282830; 
}

.btn-tool.active { 
  background: #4a505b; 
  color: #ffffff; 
  border-color: #8b93a0; 
}

.canvas-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 256px;
}

canvas#pixelCanvas { 
  background-color: #101012; 
  cursor: crosshair; 
  image-rendering: pixelated; 
  image-rendering: crisp-edges;
  border: 2px solid #303038; 
  box-sizing: border-box;
  flex-shrink: 0;
}

.canvas-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
}

.history-group {
  display: flex;
  gap: 6px;
}

.canvas-actions .btn-icon {
  padding: 6px 10px;
  background-color: #232328;
  border: 1px solid #3a3a42;
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
}

.canvas-actions .btn-icon:hover {
  background-color: #32323a;
}

.canvas-actions .btn-danger:hover {
  background-color: #a32a2a;
  border-color: #d33838;
}


/* ==========================================================
   6. RIGHT PANEL: WORKSPACE SECTION & GLYPH CATALOG
   ========================================================== */
.workspace-section { 
  flex: 1; 
  min-width: 360px; 
  display: flex; 
  flex-direction: column; 
  gap: 16px; 
  height: 100%;
  min-height: 0;
}

.workspace-switch-container {
  display: flex;
  background: transparent;
  border: none;
  padding: 0;
  gap: 4px;
  width: 100%;
  position: relative;
  z-index: 1;
}

.view-tab-btn {
  flex: 1;
  background: #101012;
  border: 2px solid #303038;
  color: #a0a0ac;
  padding: 8px 16px;
  font-size: 12px;
  font-family: inherit;
  font-weight: bold;
  cursor: pointer;
  text-align: center;
  outline: none;
  transition: all 0.1s ease;
  position: relative;
  box-shadow: none;
}

.view-tab-btn:hover {
  color: #ffffff;
  background: #18181c;
}

.view-tab-btn.active {
  background: #222228;
  color: #ffffff;
  border: 2px solid #303038;
  border-bottom: 2px solid #222228;
  margin-bottom: -2px;
  padding-top: 10px;
  z-index: 2;
}

.controls-panel {
  background: #222228;
  border: 2px solid #303038;
  padding: 12px;
  position: relative;
  z-index: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.workspace-view {
  display: none;
  width: 100%;
  flex: 1;
  min-height: 0;
}

.workspace-view.active {
  display: flex;
  flex-direction: column;
}

.category-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  width: 100%;
}

.category-tabs { 
  display: flex; 
  gap: 4px; 
  flex-wrap: wrap; 
}

.tab-btn { 
  padding: 6px 10px; 
  font-size: 11px; 
  background: #101012; 
  border: 2px solid #303038; 
  color: #a0a0ac; 
  cursor: pointer; 
  font-family: inherit;
  font-weight: bold;
  box-shadow: 0 2px 0px #08080a;
}

.tab-btn:hover { 
  color: #ffffff; 
  background: #282830; 
}

.tab-btn.active { 
  background: #ff9e3b;
  color: #101012;
  border-color: #ff9e3b;
}

.char-count-text {
  font-size: 11px;
  color: #FFF5EA;
  white-space: nowrap;
}

/* Glyph Grid & Cards Fixed Layout */
.glyph-grid { 
  display: grid; 
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); 
  gap: 8px; 
  align-items: start; /* Mengunci item agar tidak terdistorsi melempar ke bawah */
  flex: 1;
  overflow-y: scroll;
  background: #101012;
  padding: 8px;
  border: 2px solid #303038;
  scrollbar-width: thin;
  scrollbar-color: #4a505b #101012;
}

.glyph-grid::-webkit-scrollbar {
  width: 8px;
}

.glyph-grid::-webkit-scrollbar-track {
  background: #101012;
  border-left: 2px solid #303038;
}

.glyph-grid::-webkit-scrollbar-thumb {
  background: #4a505b;
  border: 1px solid #303038;
}

.glyph-grid::-webkit-scrollbar-thumb:hover {
  background: #d47028;
}

.glyph-card { 
  background: #18181c; 
  border: 2px solid #2a2a32; 
  padding: 6px; 
  display: flex; 
  flex-direction: column; 
  align-items: center; 
  justify-content: center;
  width: 100%;
  aspect-ratio: 1 / 1; /* Mengunci rasio kartu persegi seragam (A-Z & 0-9) */
  box-sizing: border-box;
  cursor: pointer; 
  transition: all 0.1s ease;
}

.glyph-card:hover { 
  border-color: #6c7380; 
  background: #24242c; 
  transform: translateY(-2px); 
}

.glyph-card.active { 
  border-color: #ff9e3b; 
  background: #4a505b; 
  box-shadow: 0 0 0 1px #ff9e3b; 
}

.glyph-card canvas { 
  background: #08080a; 
  image-rendering: pixelated; 
  margin-bottom: 4px; 
  border: 1px solid #2a2a32; 
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.glyph-card .char-label { 
  font-size: 11px; 
  color: #a0a0ac; 
  font-weight: bold; 
}

.glyph-card.active .char-label { 
  color: #ffffff; 
}


/* ==========================================================
   7. LIVE PREVIEW CONTAINER & CANVAS
   ========================================================== */
.interactive-preview-container {
  flex: 1;
  min-height: 220px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start; 
  background: #101012;
  border: 2px solid #303038;
  padding: 12px;
  overflow: auto;
  outline: none;
  cursor: text;
  transition: border-color 0.2s ease;
  scrollbar-width: thin;
  scrollbar-color: #4a505b #101012;
}

.interactive-preview-container::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.interactive-preview-container::-webkit-scrollbar-track {
  background: #101012;
  border-left: 2px solid #303038;
  border-top: 2px solid #303038;
}

.interactive-preview-container::-webkit-scrollbar-thumb {
  background: #4a505b;
  border: 1px solid #303038;
}

.interactive-preview-container::-webkit-scrollbar-thumb:hover {
  background: #d47028;
}

.interactive-preview-container:focus {
  border-color: #ff9e3b;
  box-shadow: 0 0 8px rgba(255, 158, 59, 0.2);
}

#canvasPreviewWrapper {
  display: inline-block;
  width: auto;
  height: auto;
}

#livePreviewCanvas {
  display: block;
  background: #101012;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: auto !important; 
  height: auto !important;
}


/* ==========================================================
   8. RESPONSIVE MEDIA QUERIES
   ========================================================== */
@media (max-width: 900px) {
  html, body {
    height: auto;
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body {
    padding: 12px;
  }

  .app-layout {
    flex-direction: column;
    align-items: center;
    gap: 16px;
  }

  .editor-section, 
  .workspace-section {
    width: 100%;
    min-width: 100%;
  }

  .editor-workspace {
    justify-content: center;
  }

  .glyph-grid {
    min-height: 250px;
    max-height: 350px;
  }

  .interactive-preview-container {
    min-height: 200px;
  }
}

@media (max-width: 500px) {
  body {
    padding: 8px;
  }

  header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .brand-group {
    align-items: center;
  }

  .header-actions {
    justify-content: space-between;
    width: 100%;
  }

  .header-actions button {
    padding: 6px 10px;
    font-size: 11px;
  }

  .panel {
    padding: 12px;
  }

  .editor-workspace {
    gap: 8px;
  }

  .vertical-toolbar {
    width: 32px;
  }

  .btn-tool {
    padding: 6px;
  }

  .canvas-container {
    width: 100%;
    max-width: 256px;
  }

  .category-tabs {
    gap: 2px;
  }

  .tab-btn {
    padding: 6px 8px;
    font-size: 10px;
  }

  .glyph-grid {
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
    gap: 6px;
    padding: 6px;
  }
}