* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body.tavle-page {
    background: #edf2f7;
}

#toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    min-height: 64px;
    padding: 10px 14px;
    background: rgba(248, 250, 252, 0.96);
    border-bottom: 1px solid #cbd5e1;
    flex-wrap: wrap;
}

.toolbar-actions,
.toolbar-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.toolbar-menu {
    position: relative;
}

.toolbar-menu-button {
    min-height: 42px;
}

.coordinate-panel,
.geometry-panel,
.dice-panel,
.stopwatch-panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-start;
    width: max-content;
    max-width: min(760px, calc(100vw - 28px));
    padding: 8px;
    border: 1px solid #cbd5e1;
    border-radius: 14px;
    background: rgba(248, 250, 252, 0.96);
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.14);
}

.coordinate-panel[hidden],
.geometry-panel[hidden],
.dice-panel[hidden],
.stopwatch-panel[hidden] {
    display: none !important;
}

.coord-field {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 42px;
    padding: 6px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    background: #ffffff;
    color: #1e293b;
    font-size: 14px;
    font-weight: 700;
}

.coord-field input {
    width: 92px;
    min-height: 30px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 4px 8px;
    font: inherit;
}

.coord-function-field input {
    width: 180px;
}

button {
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #1e293b;
    border-radius: 12px;
}

button:hover {
    background: #f8fafc;
}

.geometry-option-toggle.is-active {
    background: #dcfce7;
    border-color: #16a34a;
    color: #14532d;
}

.dice-option-toggle.is-active {
    background: #fef3c7;
    border-color: #d97706;
    color: #78350f;
}

.dice-panel select,
.stopwatch-panel select {
    min-height: 30px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 4px 8px;
    font: inherit;
}

.resolution-badge {
    display: inline-flex;
    align-items: center;
    min-height: 42px;
    padding: 8px 12px;
    border-radius: 12px;
    background: #dbeafe;
    color: #1d4ed8;
    font-weight: 700;
}

.fullscreen-button {
    background: #1d4ed8;
    border-color: #1d4ed8;
    color: #ffffff;
}

.fullscreen-button:hover {
    background: #1e40af;
}

.dice-roll-area {
    position: fixed;
    left: 50%;
    top: 50%;
    z-index: 40;
    width: min(760px, calc(100vw - 32px));
    max-height: calc(100vh - var(--toolbar-height, 64px) - 42px);
    padding: 18px;
    border: 1px solid #cbd5e1;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 18px 42px rgba(15, 23, 42, 0.22);
    transform: translate(-50%, -50%);
    overflow: auto;
    pointer-events: none;
}

.dice-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(54px, 1fr));
    gap: 10px;
    align-items: center;
}

.dice-roll {
    justify-self: center;
    display: grid;
    place-items: center;
    width: 68px;
    height: 68px;
    border: 3px solid #0f172a;
    border-radius: 14px;
    background: #ffffff;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.15);
    transform: scale(0.92) rotate(-8deg);
    transition: transform 140ms ease, opacity 180ms ease;
}

.dice-roll.is-rolling {
    transform: scale(1.04) rotate(8deg);
}

.dice-roll.is-done {
    transform: scale(1) rotate(0deg);
}

.dice-roll-small {
    width: 42px;
    height: 42px;
    border-width: 2px;
    border-radius: 9px;
}

.dice-face {
    position: relative;
    width: 46px;
    height: 46px;
}

.dice-roll-small .dice-face {
    width: 28px;
    height: 28px;
}

.dice-dot {
    position: absolute;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #0f172a;
    transform: translate(-50%, -50%);
}

.dice-roll-small .dice-dot {
    width: 6px;
    height: 6px;
}

.dice-dot[data-position="1"] { left: 24%; top: 24%; }
.dice-dot[data-position="2"] { left: 50%; top: 24%; }
.dice-dot[data-position="3"] { left: 76%; top: 24%; }
.dice-dot[data-position="4"] { left: 24%; top: 50%; }
.dice-dot[data-position="5"] { left: 50%; top: 50%; }
.dice-dot[data-position="6"] { left: 76%; top: 50%; }
.dice-dot[data-position="7"] { left: 24%; top: 76%; }
.dice-dot[data-position="8"] { left: 50%; top: 76%; }
.dice-dot[data-position="9"] { left: 76%; top: 76%; }

.dice-stats {
    display: grid;
    gap: 10px;
    margin-top: 14px;
    color: #0f172a;
    font-size: 15px;
    font-weight: 700;
}

.dice-stat-box {
    padding: 10px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #f8fafc;
}

.dice-pair-list {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.dice-pair {
    padding: 6px 8px;
    border-radius: 8px;
    background: #dbeafe;
    color: #1e3a8a;
}

.dice-pair.is-seven,
.dice-matrix .is-seven {
    background: #dcfce7;
    color: #14532d;
    font-weight: 800;
}

.dice-frequency-row {
    display: grid;
    grid-template-columns: 34px 1fr 34px;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}

.dice-frequency-bar {
    height: 12px;
    border-radius: 999px;
    background: #f59e0b;
}

.dice-frequency-bar.is-seven {
    background: #16a34a;
}

.dice-matrix {
    border-collapse: collapse;
    margin-top: 8px;
    font-size: 13px;
}

.dice-matrix th,
.dice-matrix td {
    width: 28px;
    height: 24px;
    border: 1px solid #cbd5e1;
    text-align: center;
}

.dice-matrix th {
    background: #e0f2fe;
}

.dice-matrix-modal {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: grid;
    place-items: center;
    padding: 28px;
    background: rgba(15, 23, 42, 0.38);
}

.dice-matrix-modal[hidden] {
    display: none !important;
}

.dice-matrix-dialog {
    position: relative;
    width: min(760px, calc(100vw - 42px));
    padding: 22px;
    border-radius: 16px;
    background: #ffffff;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.32);
}

.dice-matrix-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: 50%;
    font-size: 24px;
    line-height: 1;
}

.dice-matrix-title {
    margin: 0 44px 16px 0;
    color: #0f172a;
    font-size: 22px;
}

.dice-matrix-modal .dice-matrix {
    width: 100%;
    font-size: 20px;
}

.dice-matrix-modal .dice-matrix th,
.dice-matrix-modal .dice-matrix td {
    width: auto;
    height: 58px;
}

.timer-card {
    position: fixed;
    left: 50%;
    top: 50%;
    z-index: 35;
    display: grid;
    justify-items: center;
    gap: 12px;
    min-width: 310px;
    padding: 26px;
    border: 1px solid #cbd5e1;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 18px 42px rgba(15, 23, 42, 0.2);
    color: #0f172a;
    transform: translate(-50%, -50%);
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.timer-card.is-dragging {
    cursor: grabbing;
}

.timer-ring {
    position: relative;
    display: grid;
    place-items: center;
    width: 220px;
    height: 220px;
    border-radius: 50%;
    background:
        conic-gradient(from -90deg, #e2e8f0 calc((1 - var(--timer-progress, 1)) * 1turn), var(--timer-color, #16a34a) 0);
}

.timer-ring::after {
    content: "";
    position: absolute;
    inset: 17px;
    border-radius: 50%;
    background: #ffffff;
}

.timer-icon {
    position: relative;
    z-index: 1;
    color: #0f172a;
    font-size: 64px;
    font-weight: 800;
}

.timer-time {
    font-size: 42px;
    font-weight: 800;
}

.timer-label {
    font-size: 15px;
    font-weight: 700;
    color: #475569;
}

.timer-card.is-finished .timer-ring {
    background: conic-gradient(#dc2626 1turn, #dc2626 0);
}

.time-widget {
    position: fixed;
    left: 50%;
    top: 50%;
    z-index: 34;
    transform: translate(-50%, -50%);
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.time-widget-close {
    position: absolute;
    top: -12px;
    right: -12px;
    z-index: 3;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 2px solid #ffffff;
    border-radius: 50%;
    background: #0f172a;
    color: #ffffff;
    font-size: 22px;
    line-height: 1;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.22);
    cursor: pointer;
}

.time-widget.is-dragging {
    cursor: grabbing;
}

.analog-clock,
.digital-clock {
    display: grid;
    place-items: center;
    border: 1px solid #cbd5e1;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 18px 42px rgba(15, 23, 42, 0.2);
}

.analog-clock {
    position: relative;
    width: 250px;
    height: 250px;
    border-radius: 50%;
}

.clock-number {
    position: absolute;
    left: 50%;
    top: 50%;
    font-size: 20px;
    font-weight: 800;
    color: #0f172a;
    transform:
        rotate(calc(var(--n) * 30deg))
        translateY(-102px)
        rotate(calc(var(--n) * -30deg))
        translate(-50%, -50%);
}

.clock-hand {
    position: absolute;
    left: 50%;
    bottom: 50%;
    width: 6px;
    border-radius: 999px;
    background: #0f172a;
    transform-origin: bottom center;
    transform: translateX(-50%) rotate(var(--angle, 0deg));
}

.clock-hour {
    height: 62px;
}

.clock-minute {
    height: 86px;
    width: 4px;
}

.clock-second {
    height: 94px;
    width: 2px;
    background: #dc2626;
}

.clock-center {
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #0f172a;
}

.digital-clock {
    min-width: 330px;
    padding: 26px 34px;
    border-radius: 18px;
    color: #0f172a;
    font-size: 64px;
    font-weight: 900;
    letter-spacing: 0;
}

.cat-clock {
    position: relative;
    width: 220px;
    height: 430px;
    filter: drop-shadow(0 18px 28px rgba(15, 23, 42, 0.25));
}

.cat-head,
.cat-body,
.cat-tail {
    position: absolute;
    background: #111827;
}

.cat-head {
    left: 35px;
    top: 0;
    width: 150px;
    height: 125px;
    border-radius: 48% 48% 44% 44%;
}

.cat-head::before,
.cat-head::after {
    content: "";
    position: absolute;
    top: -24px;
    width: 48px;
    height: 58px;
    background: #111827;
    clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.cat-head::before { left: 4px; transform: rotate(-18deg); }
.cat-head::after { right: 4px; transform: rotate(18deg); }

.cat-eye {
    position: absolute;
    top: 34px;
    width: 48px;
    height: 34px;
    border-radius: 70% 18% 70% 18%;
    background: #f8fafc;
    overflow: hidden;
    transform: rotate(-8deg);
}

.cat-eye-left { left: 32px; }
.cat-eye-right { right: 32px; transform: rotate(8deg) scaleX(-1); }

.cat-pupil {
    position: absolute;
    left: 20px;
    top: 7px;
    width: 8px;
    height: 21px;
    border-radius: 50%;
    background: #0f172a;
    animation: cat-pupil-sway 2.4s ease-in-out infinite alternate;
}

.cat-nose {
    position: absolute;
    left: 50%;
    top: 76px;
    width: 18px;
    height: 14px;
    border-radius: 50%;
    background: #334155;
    transform: translateX(-50%);
}

.cat-smile {
    position: absolute;
    left: 50%;
    top: 90px;
    width: 68px;
    height: 26px;
    border-bottom: 4px solid #f8fafc;
    border-radius: 50%;
    transform: translateX(-50%);
}

.cat-body {
    left: 30px;
    top: 112px;
    width: 160px;
    height: 190px;
    border-radius: 34px 34px 22px 22px;
}

.cat-bow {
    position: absolute;
    left: 50%;
    top: 118px;
    width: 80px;
    height: 28px;
    transform: translateX(-50%);
}

.cat-bow::before,
.cat-bow::after {
    content: "";
    position: absolute;
    width: 38px;
    height: 24px;
    border-radius: 50% 10% 50% 10%;
    background: #f8fafc;
}

.cat-bow::before { left: 0; transform: rotate(18deg); }
.cat-bow::after { right: 0; transform: rotate(-18deg); }

.cat-face-clock {
    position: absolute;
    left: 50%;
    top: 152px;
    width: 112px;
    height: 112px;
    border: 4px solid #f8fafc;
    border-radius: 18px;
    background: #1f2937;
    transform: translateX(-50%);
}

.cat-face-clock .clock-number {
    color: #f8fafc;
    font-size: 14px;
    transform:
        rotate(calc(var(--n) * 30deg))
        translateY(-44px)
        rotate(calc(var(--n) * -30deg))
        translate(-50%, -50%);
}

.cat-face-clock .clock-hand {
    background: #f8fafc;
}

.cat-face-clock .clock-hour { height: 28px; width: 5px; }
.cat-face-clock .clock-minute { height: 40px; width: 3px; }
.cat-face-clock .clock-second { height: 44px; width: 2px; background: #facc15; }
.cat-face-clock .clock-center { background: #facc15; width: 12px; height: 12px; }

.cat-tail {
    left: 96px;
    top: 288px;
    width: 30px;
    height: 150px;
    border-radius: 0 0 22px 22px;
    transform-origin: 50% 0;
    animation: cat-tail-swing 1.45s ease-in-out infinite alternate;
}

@keyframes cat-tail-swing {
    from { transform: rotate(-9deg); }
    to { transform: rotate(9deg); }
}

@keyframes cat-pupil-sway {
    from { transform: translateX(-7px); }
    to { transform: translateX(7px); }
}

#canvasContainer {
    width: 100%;
    height: calc(100vh - var(--toolbar-height, 64px));
    position: relative;
    background: #ffffff;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    border: 1px solid #cbd5e1;
    background: #ffffff;
}

body.is-presenter #toolbar {
    background: rgba(241, 245, 249, 0.98);
}

@media (max-width: 900px) {
    #toolbar {
        padding: 10px;
    }

    #canvasContainer {
        height: calc(100vh - var(--toolbar-height, 64px));
    }

    .coordinate-panel,
    .geometry-panel,
    .dice-panel,
    .stopwatch-panel {
        max-width: calc(100vw - 20px);
    }

    .toolbar-actions .toolbar-menu:last-of-type .toolbar-dropdown {
        left: auto;
        right: 0;
    }
}
