:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-strong: #e8eef2;
  --ink: #17212b;
  --muted: #667482;
  --line: #d9e1e7;
  --accent: #226f54;
  --accent-strong: #1a5a44;
  --focus: #f2a900;
  --shadow: 0 14px 35px rgba(23, 33, 43, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 30px clamp(16px, 4vw, 32px) 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 3.2rem);
  line-height: 1.05;
  letter-spacing: 0;
}

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 32px) 48px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button,
.back-link,
.download-link {
  display: inline-grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 6px 18px rgba(23, 33, 43, 0.06);
  cursor: pointer;
  text-decoration: none;
}

.icon-button:hover,
.back-link:hover,
.download-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.icon-button:focus-visible,
.back-link:focus-visible,
.download-link:focus-visible,
.card-button:focus-visible,
.search-field:focus-within,
select:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 45%, transparent);
  outline-offset: 2px;
}

.icon-button.is-loading span {
  animation: spin 0.8s linear infinite;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(160px, 230px);
  gap: 12px;
  margin: 12px 0 14px;
}

.search-field {
  display: flex;
  align-items: center;
  min-width: 0;
  height: 50px;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 0 16px;
}

.search-field span {
  color: var(--muted);
  font-size: 1.2rem;
}

.search-field input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

select {
  min-width: 0;
  height: 50px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 14px;
}

.library-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  min-height: 24px;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 0.92rem;
}

#folderLabel {
  overflow: hidden;
  max-width: 100%;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
}

.ggb-card {
  min-width: 0;
}

.card-button {
  display: grid;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 0;
  text-align: left;
  box-shadow: 0 10px 26px rgba(23, 33, 43, 0.07);
  cursor: pointer;
}

.card-button:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  box-shadow: var(--shadow);
}

.preview-wrap {
  display: block;
  aspect-ratio: 16 / 10.5;
  background: var(--surface-strong);
}

.preview {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-copy {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 13px 14px 15px;
}

.card-title {
  overflow: hidden;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  margin-top: 22px;
  border: 1px dashed #b4c3cf;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  padding: 34px 18px;
  text-align: center;
}

.empty-state h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

.viewer-page {
  overflow: hidden;
}

.viewer-shell {
  display: grid;
  width: 100%;
  max-width: none;
  height: 100dvh;
  padding: 0;
  grid-template-rows: auto minmax(0, 1fr);
}

.viewer-topbar {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 52px;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  padding: 10px clamp(10px, 2vw, 18px);
}

.viewer-topbar h1 {
  overflow: hidden;
  font-size: 1.05rem;
  line-height: 1.2;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.back-link,
.download-link {
  width: 44px;
  height: 44px;
  box-shadow: none;
  font-size: 1.7rem;
}

.download-link {
  font-size: 1.35rem;
}

.applet-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: #ffffff;
}

#ggbApplet {
  width: 100%;
  height: 100%;
}

.viewer-message {
  position: absolute;
  inset: 50% auto auto 50%;
  margin: 0;
  transform: translate(-50%, -50%);
  color: var(--muted);
  font-weight: 700;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 720px) {
  .app-header {
    align-items: flex-start;
    padding-top: 22px;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
    gap: 12px;
  }

  .card-copy {
    padding: 11px 12px 13px;
  }

  .card-title {
    font-size: 0.94rem;
  }

  .viewer-topbar {
    grid-template-columns: 46px minmax(0, 1fr) 46px;
  }
}

@media (pointer: coarse) {
  .icon-button,
  .back-link,
  .download-link {
    min-width: 46px;
    min-height: 46px;
  }
}
